{ "info": { "author": "Aur\u00e9lien", "author_email": "aurelien@clustaar.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Programming Language :: Python" ], "description": "# clustaar.webhook\n\nclustaar.webhook is a framework for building webhooks for the [clustaar platform](https://clustaar.com).\n\nMore documentation is available for building webhooks on https://developers.clustaar.com\n\n## Example\n\nHere is a webhook that will trigger an `handler` function each times it receives a `conversation.step_reached` event.\n\n```python\nfrom clustaar.webhook import Webhook, events\nfrom clustaar.schemas.models import StepReachedResponse, ConversationSession\n\ndef handler(request, response, notification):\n session = ConversationSession(values={\"name\": \"John\"})\n return StepReachedResponse(actions=[], session=session)\n\n\napp = Webhook()\napp.on(events.CONVERSATION_STEP_REACHED, handler)\n```\n## Routing\n### Event\nRouting is achieved by specifying an event name to the `on()` method while configuring your webhook :\n```python\napp.on(events.CONVERSATION_STEP_REACHED, handler)\n```\n\n### Filters\n\nIf you want to add some condition to route events based on the request received you can use filters.\n\nIn this example, `handler` will receive the requests only when the event is of type `events.CONVERSATION_STEP_REACHED` and the value of the JSON key `data.step.id` equals `\"507f191e810c19729de860ea\"` : \n```python\nfrom clustaar.webhook.filters import JSONKeyEquals\napp.on(events.CONVERSATION_STEP_REACHED,\n handler,\n filter=JSONKeyEquals(\"data.step.id\", \"507f191e810c19729de860ea\"))\n```\n\n#### JSONKeyEquals\n\nValidates that a JSON key equals an expected value.\n```python\ndata = {\n \"user\": {\n \"id\": 1\n }\n}\nfilter = JSONKeyEquals(\"user.id\", 1)\nassert filter(data)\ndata[\"user\"][\"id\"] = 2\nassert not filter(data)\n```\n\n#### JSONKeyIn\n\nValidates that a key is present in a defined set of values.\n```python\ndata = {\n \"user\": {\n \"id\": 1\n }\n}\nfilter = JSONKeyIn(\"user.id\", [1, 2])\nassert filter(data)\ndata[\"user\"][\"id\"] = 2\nassert filter(data)\ndata[\"user\"][\"id\"] = 3\nassert not filter(data)\n```\n\n#### JSONKeyExists\n\nValidates that a JSON key is present.\n```python\ndata = {\n \"user\": {\n \"id\": 1\n }\n}\nfilter = JSONKeyExists(\"user.id\")\nassert filter(data)\ndel data[\"user\"][\"id\"]\nassert not filter(data)\n```\n\n#### StepID\n\nValidates that the `data.step.id` correspond to the expected id.\n```python\ndata = {\n\t\"data\": {\n\t \"step\": {\n\t \"id\": \"507f191e810c19729de860ea\"\n\t }\n }\n}\nfilter = StepID(\"507f191e810c19729de860ea\")\nassert filter(data)\ndel data[\"data\"][\"step\"][\"id\"]\nassert not filter(data)\n```\nIf you pass a list of step IDs to the `StepID` filter it will validate the the `data.step.id` is present in the list.\n\n## Security\n\n### Request signature\nIf you want to validate the signature of the requests sent by clustaar, you need to provide a private key. \nThis private key must be set in your bot's webhook configuration.\n\n```python\napp = Webhook(private_key=\"XXXXXXXXXX\")\n```\n\n### Authentication\nIf you want to add some authentication to your application you can pass the HTTP basic authentication credentials that you defined in your webhook's configuration.\n\n```python\napp = Webhook(auth_username=\"XXXXXXXXXX\", auth_password=\"YYYYYYYYY\")\n```\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Clustaar/clustaar.webhook", "keywords": "", "license": "mit", "maintainer": "", "maintainer_email": "", "name": "clustaar.webhook", "package_url": "https://pypi.org/project/clustaar.webhook/", "platform": "any", "project_url": "https://pypi.org/project/clustaar.webhook/", "project_urls": { "Homepage": "https://github.com/Clustaar/clustaar.webhook" }, "release_url": "https://pypi.org/project/clustaar.webhook/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Clustaar webhook framework", "version": "0.1.2" }, "last_serial": 3695937, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "5c5d933ef80ee34901dd5f3c03a24449", "sha256": "ecb7a68a6acc0a1c26bb24e0d48a974813e02a4d3355f95f78dca7680cfbd6ab" }, "downloads": -1, "filename": "clustaar.webhook-0.1.0.tar.gz", "has_sig": false, "md5_digest": "5c5d933ef80ee34901dd5f3c03a24449", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21390, "upload_time": "2018-02-27T10:59:55", "url": "https://files.pythonhosted.org/packages/3e/02/eab835ed855ba63c5f3644c094bab8c7824bbdbe1d4082a58483ad15a525/clustaar.webhook-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "4fea2bceb1c1ccad1cf1660fd2c8fda9", "sha256": "5b52e4b0d6ba4e2f3de5f501690c55414f3504f830f7c2e2ea4deea2059d90f0" }, "downloads": -1, "filename": "clustaar.webhook-0.1.1.tar.gz", "has_sig": false, "md5_digest": "4fea2bceb1c1ccad1cf1660fd2c8fda9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21499, "upload_time": "2018-03-01T15:41:38", "url": "https://files.pythonhosted.org/packages/9c/b0/642ba38023a789e03581f768e365b8acac0545911fd059e11eb8bcf0623a/clustaar.webhook-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "69dcbb04eaf24e615b5e18d9462e24e8", "sha256": "290f980d3d77648a33bb0185290081abd7db537b4982050ca32c7dbb8760c413" }, "downloads": -1, "filename": "clustaar.webhook-0.1.2.tar.gz", "has_sig": false, "md5_digest": "69dcbb04eaf24e615b5e18d9462e24e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21505, "upload_time": "2018-03-22T16:12:08", "url": "https://files.pythonhosted.org/packages/8f/ef/133194affd96f0fc6f62f5082489337dfc16ff390f9849d6933676f81b75/clustaar.webhook-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "69dcbb04eaf24e615b5e18d9462e24e8", "sha256": "290f980d3d77648a33bb0185290081abd7db537b4982050ca32c7dbb8760c413" }, "downloads": -1, "filename": "clustaar.webhook-0.1.2.tar.gz", "has_sig": false, "md5_digest": "69dcbb04eaf24e615b5e18d9462e24e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21505, "upload_time": "2018-03-22T16:12:08", "url": "https://files.pythonhosted.org/packages/8f/ef/133194affd96f0fc6f62f5082489337dfc16ff390f9849d6933676f81b75/clustaar.webhook-0.1.2.tar.gz" } ] }