{ "info": { "author": "Paoro", "author_email": "paoro.biz@outlook.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Flask", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Communications :: Chat", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Application Frameworks" ], "description": "# API.AI Webhook ![Travis CI build status image for master branch](https://travis-ci.org/paoro-solutions/apiaiwebhook.svg?branch=master)\r\n\r\nAPI.AI Webhook is a fulfillment microframework for [API.AI](https://api.ai/) based on [Flask](http://flask.pocoo.org/) for getting started quickly with API.AI [webhooks](https://docs.api.ai/docs/webhook). \r\n\r\n## Users' Guide \r\n\r\n### Quick Start\r\n\r\nInstall the package with \r\n\r\n pip install apiaiwebhook\r\n\r\nA minimal api.ai Webhook application looks like this:\r\n\r\n from apiaiwebhook import APIAIWebhook\r\n app = APIAIWebhook(__name__)\r\n\r\n @app.fulfillment(\"hello-world\")\r\n def hello_world():\r\n return app.make_response_apiai(speech=\"Hello World!\")\r\n\r\n if __name__ == '__main__':\r\n app.run()\r\n\r\nTo run the application, just execute the python file:\r\n\r\n python hello_world.py\r\n\r\nTo test the application, you can use either the in-built api.ai test client\r\n\r\n app.testing = True\r\n res = app.test_client_apiai().webhook(action=\"hello-world\"})\r\n assert res.status_code == 200\r\n assert \"\"Hello, World!\" in res.data\r\n\r\nOr you can use curl\r\n\r\n curl -X POST -H \"Content-Type: application/json\" -d '{\"result\": {\"action\": \"hello-world\"}}' http://127.0.0.1:5000/webhook\r\n\r\n### Parameters\r\n\r\nThe parameters are extracted from `results/parameters`.\r\nThis dictionary is passed to the fulfillment function via `**` operator (unpacked):\r\n\r\n {\r\n \"results\": {\r\n \"action\": \"hello-world\",\r\n \"parameters\": {\r\n \"parameter\": \"example value\"\r\n }\r\n }\r\n }\r\n\r\nThe fulfillment function declaration should look like this:\r\n\r\n @app.fulfillment(\"hello-world\")\r\n def hello_world(parameter = None, **kwargs):\r\n return app.make_response_apiai(speech=\"Hello, %s!\" % parameter)\r\n\r\nThe default value is required when the parameter can be empty.\r\nKwargs is useful when additional parameters are expected in the future.\r\n\r\n### Response\r\nThe webhook dispatcher responses:\r\n\r\n* HTTP 400 when `api_key_value` is defined but it the authentication header is not provided.\r\n* HTTP 401 when `api_key_value` is defined but it is invalid.\r\n* HTTP 404 when fulfillment function is not defined for the provided action.\r\n\r\nOtherwise it returns a valid application/json content-type HTTP response.\r\nThe response can be create using the helper function of `make_response_apiai()`\r\n\r\nExample:\r\n\r\n @app.fulfillment(\"hello-world\")\r\n def my_fulfillment_none():\r\n return app.make_response_apiai(speech=\"Hello, World!\"\r\n display_text=\"Hello, World! I am please to meet you!\")\r\n\r\nThe response will be like:\r\n\r\n {\r\n \"speech\": \"Hello, World!\",\r\n \"displayText\": \"Hello, World! I am please to meet you!\",\r\n \"data\": None,\r\n \"contextOut\": [],\r\n \"source\": ,\r\n \"followupEvent\": None\r\n }\r\n\r\n### Securing\r\nThe `APIAIWebhook` class defines the initialization parameters of `api_key_header` (default is `api-key`) and `api_key_value` (default is `None`) parameters.\r\n\r\nIn order to secure your webhook, define a shared secret:\r\n\r\n from apiaiwebhook import APIAIWebhook\r\n app = APIAIWebhook(__name__, api_key_value=\"secret\")\r\n\r\nThen configure the authentication header in your API.AI agent.\r\n\r\n### Testing\r\n\r\nThe API.AI Webhook Client extends the Flask Client in order to post valid webhook messages.\r\n\r\n app.testing = True\r\n app.debug = True\r\n r = app.test_client_apiai().webhook(action=\"hello-world\",\r\n parameters={\"param\": \"value\"})\r\n\r\n### Flask\r\nThe `APIAIWebhook` class is derived from `Flask`. Visit the official [website](http://flask.pocoo.org/) to extend the functionality of API.AI Webhook \r\n\r\n## Development\r\n\r\nBefore running or deploying this application, install the framework using\r\n[pip](http://pip.readthedocs.io/en/stable/):\r\n\r\n pip install -e .\r\n\r\nTo test the framework, execute the unit tests via:\r\n\r\n python unit_tests.py\r\n\r\n\r\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/paoro-solutions/apiaiwebhook", "keywords": "api.ai fullfillment webhook rest restful webservice dispatcher framework flask", "license": "GPLv3", "maintainer": "", "maintainer_email": "", "name": "apiaiwebhook", "package_url": "https://pypi.org/project/apiaiwebhook/", "platform": "", "project_url": "https://pypi.org/project/apiaiwebhook/", "project_urls": { "Homepage": "https://github.com/paoro-solutions/apiaiwebhook" }, "release_url": "https://pypi.org/project/apiaiwebhook/0.1.0.dev2/", "requires_dist": [ "Flask (>=0.12.0)" ], "requires_python": "", "summary": "API.AI Webhook is a fulfillment microframework for API.AI based on Flask for getting started quickly with API.AI webhooks.", "version": "0.1.0.dev2" }, "last_serial": 2960741, "releases": { "0.1.0.dev1": [ { "comment_text": "", "digests": { "md5": "f18d651490f7234dd43860f5b08d2ad3", "sha256": "b29c725afcd3deb3635288948c05188324ba46613e95c4eeb591aa8e170169e4" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f18d651490f7234dd43860f5b08d2ad3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 18080, "upload_time": "2017-06-15T20:58:54", "url": "https://files.pythonhosted.org/packages/f3/84/f5b101840ffcb2e8c17ffecf7e6e89301fa10803a3e14491f43e1a116a81/apiaiwebhook-0.1.0.dev1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39370fd0bc85cc46db0a90e8205d36ce", "sha256": "a1ba68f6cd67ed99617a7cb2ccd50326cd4b24c04e95140eca5fd469332dcbc5" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev1.tar.gz", "has_sig": false, "md5_digest": "39370fd0bc85cc46db0a90e8205d36ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17949, "upload_time": "2017-06-15T20:58:56", "url": "https://files.pythonhosted.org/packages/74/60/93559ee56beb0d6656a40e73842f96f862268f0cce57adb2a9139b497d55/apiaiwebhook-0.1.0.dev1.tar.gz" } ], "0.1.0.dev2": [ { "comment_text": "", "digests": { "md5": "9ba522b614f2457f1478883f1c455292", "sha256": "c6c383be8b05f52cd70ed4600104149dd152c7bf2d4a169873930909d484ea9a" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9ba522b614f2457f1478883f1c455292", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 21996, "upload_time": "2017-06-19T21:47:55", "url": "https://files.pythonhosted.org/packages/4a/4d/01fd576032810b1e18faa771c082f2d1f42ac5c6d75d52718061d2f25247/apiaiwebhook-0.1.0.dev2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9f25b464bcf7dc4d89de5d004fa2563", "sha256": "7496a37aa0db62eb7ec22f55b338cb926758adcf4f04dde5e495dace8d0c400f" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev2.tar.gz", "has_sig": false, "md5_digest": "c9f25b464bcf7dc4d89de5d004fa2563", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19987, "upload_time": "2017-06-19T21:47:57", "url": "https://files.pythonhosted.org/packages/3c/c3/d21578a35adcf467d285129f4d196aab6d23cb5eb0a7ad9ce81ee286b5eb/apiaiwebhook-0.1.0.dev2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9ba522b614f2457f1478883f1c455292", "sha256": "c6c383be8b05f52cd70ed4600104149dd152c7bf2d4a169873930909d484ea9a" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9ba522b614f2457f1478883f1c455292", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 21996, "upload_time": "2017-06-19T21:47:55", "url": "https://files.pythonhosted.org/packages/4a/4d/01fd576032810b1e18faa771c082f2d1f42ac5c6d75d52718061d2f25247/apiaiwebhook-0.1.0.dev2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9f25b464bcf7dc4d89de5d004fa2563", "sha256": "7496a37aa0db62eb7ec22f55b338cb926758adcf4f04dde5e495dace8d0c400f" }, "downloads": -1, "filename": "apiaiwebhook-0.1.0.dev2.tar.gz", "has_sig": false, "md5_digest": "c9f25b464bcf7dc4d89de5d004fa2563", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19987, "upload_time": "2017-06-19T21:47:57", "url": "https://files.pythonhosted.org/packages/3c/c3/d21578a35adcf467d285129f4d196aab6d23cb5eb0a7ad9ce81ee286b5eb/apiaiwebhook-0.1.0.dev2.tar.gz" } ] }