{ "info": { "author": "Jean Pimentel", "author_email": "contato@jeanpimentel.com.br", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Communications", "Topic :: Software Development :: Libraries" ], "description": "# A framework for Google Hangouts Chat Bot\n\n[![Build Status](https://travis-ci.org/ciandt/google-hangouts-chat-bot.svg?branch=master)](https://travis-ci.org/ciandt/google-hangouts-chat-bot)\n[![Current version at PyPI](https://img.shields.io/pypi/v/google-hangouts-chat-bot.svg)](https://pypi.python.org/pypi/google-hangouts-chat-bot)\n![Supported Python Versions](https://img.shields.io/pypi/pyversions/google-hangouts-chat-bot.svg)\n![PyPI status](https://img.shields.io/pypi/status/google-hangouts-chat-bot.svg)\n[![License: MIT](https://img.shields.io/pypi/l/google-hangouts-chat-bot.svg)](https://github.com/ciandt/google-hangouts-chat-bot/blob/master/LICENSE)\n\nThis is a framework you can use to build bots for Google Hangouts Chat. (You can read more about Google Hangouts Chat below.)\n\nIt was made to be simple and extensible.\n\n## What it does?\n\nThere are many ways to create a bot for Google Hangouts Chat and one of them is using HTTP endpoints.\nIn a nutshell, the bot receives a JSON payload via an HTTP POST request and should respond it with another JSON, following a defined message format.\n\nThis framework was built to facilitate the creation of _cli_-like bots. It parses the payload and verifies if there is some command associated with the message. If there is one, this command is called and the result is returned. \n\nThe main pieces are:\n- `Command`: our base command class\n- `Commands`: a collection of commands\n- `EventHandler`: the core, responsible to parse the message and call the associated command.\n \nIn addition to that, we have:\n- response helpers: to create the responses with the right format.\n\t- `create_text_response()`\n\t- `create_cards_response()`\n\t- `create_card_header()`\n\t- `create_card_paragraph()`\n\t- `create_card_key_value()`\n\t- `create_card_image()`\n\t- `create_card_buttons()`\n\t- `create_card_text_button`\n\t- `create_card()`\n\t\n- security helpers:\n - `check_allowed_domain` - to verify if user can use the bot\n - `check_bot_authenticity` - to verify if the request was made by a real bot\n\t\n- built-in `Help` command:\n\nWhen invoked, it will return a message with available commands (example):\n\n```\nCommands available:\n\nhello \nSay hello\n\nsum ...\nSum informed values\n\n# Repeat for every non-hidden command\n# [command] [arguments]\n# [description]\n\nhelp\nList commands available\n\nHINT: If you need to specify multiple words for a parameter, use quotes (\").\n```\n\n### Atention\n\n- This framework is not a web framework. You need to use it with one solution.\n\nExample using _Flask_:\n```python\n@app.route(\"/\", methods=[\"POST\"])\ndef main():\n payload = request.get_json()\n response = EventHandler(payload, commands).process()\n return json.jsonify(response)\n```\n\n## How it works?\n\n1 - `Command` _(our base class)_:\n\n```python\nclass Command:\n # the keyword that will trigger it\n command = None \n \n # some aliases, if needed\n command_aliases = []\n \n # description of expected arguments\n arguments = None\n \n # description of command\n description = None\n\n # if hidden, this command will not appear when listing commands\n hidden = False\n \n # main method\n def handle(self, arguments, **kwargs):\n raise NotImplementedError\n```\n\n1.1 - Let's create a *Hello* command:\n```python\nclass Hello(Command):\n command = \"hello\"\n command_aliases = [\"hi\", \"hey\"]\n arguments = \"\"\n description = \"Say hello\"\n\n def handle(self, arguments, **kwargs):\n return create_text_response(f\"Hello, {arguments[0]}!\")\n```\n\n2 - `Commands`:\n\n```python\n# Creating a list of available commands \ncommands = Commands()\ncommands.add_command(Hello)\n\n# if needed, you can add commands by module\ncommands.add_commands_from_module(some.module)\n```\n\n3 - `EventHandler`:\n\n```python\npayload = {...}\n\n# it receives the payload, commands list and more kwargs if needed\n# then it processes the payload, returning a response\nresponse = EventHandler(payload, commands).process()\n```\n\n4 - Sending a \"hello\" message:\n```python\ncommands = Commands()\ncommands.add_command(Hello)\n\npayload = {\n \"type\": \"MESSAGE\",\n \"message\": {\"text\": \"hello Jane\"}, # what the user has typed\n \"space\": \"...\",\n \"user\": \"...\",\n}\n\n# message will be parsed, identifying:\n# command = \"hello\" \n# arguments = [\"Jane\"]\n# \n# since we have a command triggered by \"hello\"\n# \n# class Hello(Command):\n# command = \"hello\"\n# ...\n# \n# an instance will be created and called:\n# return Hello().handle(arguments) \n\nresponse = EventHandler(payload, commands).process()\n\nprint(response) \n{\"text\": \"Hello, Jane!\"}\n```\n\n## Google Hangouts Chat\n\nThe following diagram describes a typical interaction with a bot in a chat room:\n\n![Flow diagram](https://developers.google.com/hangouts/chat/images/bot-room-seq.png)\n\n* [Design guidelines](https://developers.google.com/hangouts/chat/concepts/ux)\n* [Creating new bots](https://developers.google.com/hangouts/chat/how-tos/bots-develop)\n* [Publishing bots](https://developers.google.com/hangouts/chat/how-tos/bots-publish)\n* [Hangouts Chat message formats](https://developers.google.com/hangouts/chat/reference/message-formats/)\n\n\n## Installing\n\nYou can install using [pip](https://pip.pypa.io/en/stable/):\n\n```\n$ python -m pip install google_hangouts_chat_bot\n```\n\n\n## Authors\n\n- [@jeanpimentel](https://github.com/jeanpimentel) (Jean Pimentel)\n\n\n## Contributing\n\nContributions are always welcome and highly encouraged.\nSee [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started.\n\n\n## License\n\nMIT - See [the LICENSE](LICENSE) for more information.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ciandt/google-hangouts-chat-bot", "keywords": "google hangouts chat chatbot", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "google-hangouts-chat-bot", "package_url": "https://pypi.org/project/google-hangouts-chat-bot/", "platform": "", "project_url": "https://pypi.org/project/google-hangouts-chat-bot/", "project_urls": { "Homepage": "https://github.com/ciandt/google-hangouts-chat-bot" }, "release_url": "https://pypi.org/project/google-hangouts-chat-bot/0.2.0/", "requires_dist": null, "requires_python": ">=3.7", "summary": "A framework for Google Hangouts Chat Bot", "version": "0.2.0", "yanked": false, "yanked_reason": null }, "last_serial": 6210754, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "fbe3248515ded3ca8c30c1877bc3d75b", "sha256": "05158599764a687b2c6591f64d9096973711216ca733a385d682ddae36bd9ff2" }, "downloads": -1, "filename": "google-hangouts-chat-bot-0.1.3.tar.gz", "has_sig": false, "md5_digest": "fbe3248515ded3ca8c30c1877bc3d75b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 6134, "upload_time": "2019-10-31T12:43:00", "upload_time_iso_8601": "2019-10-31T12:43:00.312631Z", "url": "https://files.pythonhosted.org/packages/c1/4e/883e34ab1422ab989371c7947d673d7a13314efc47b6d31c9cab91aafb09/google-hangouts-chat-bot-0.1.3.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "3660bcbe1919a80db7b04842e512bc1e", "sha256": "3150282da0bb9500794dc29708ba0680fb0e3292db3566d6a03bf7b274d72d32" }, "downloads": -1, "filename": "google-hangouts-chat-bot-0.1.4.tar.gz", "has_sig": false, "md5_digest": "3660bcbe1919a80db7b04842e512bc1e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 6162, "upload_time": "2019-11-04T23:14:44", "upload_time_iso_8601": "2019-11-04T23:14:44.326042Z", "url": "https://files.pythonhosted.org/packages/52/c5/079237e3168ccedb96fbbcff524cbf7d8e1692567e79c7ed306516973249/google-hangouts-chat-bot-0.1.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "50b411b4276fe637a6d37b65fb19e923", "sha256": "d6e7f35c39e2dfbbc5abe0fdf27dbe0925dd9d04acd17a27ba8cb49f95a17cf9" }, "downloads": -1, "filename": "google-hangouts-chat-bot-0.1.5.tar.gz", "has_sig": false, "md5_digest": "50b411b4276fe637a6d37b65fb19e923", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 6179, "upload_time": "2019-11-06T18:33:48", "upload_time_iso_8601": "2019-11-06T18:33:48.162655Z", "url": "https://files.pythonhosted.org/packages/3c/4e/808ce52a891ca79f65de895c8b17c3f30849943752c15aa687ff77327dfd/google-hangouts-chat-bot-0.1.5.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "ea0379f7c196e4d0d4b291d1a64f8dec", "sha256": "029ad033643892d7c613ee07214f3f14fc496a824c4fb5fa2545091d5c570b60" }, "downloads": -1, "filename": "google-hangouts-chat-bot-0.2.0.tar.gz", "has_sig": false, "md5_digest": "ea0379f7c196e4d0d4b291d1a64f8dec", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9443, "upload_time": "2019-11-27T21:01:14", "upload_time_iso_8601": "2019-11-27T21:01:14.680684Z", "url": "https://files.pythonhosted.org/packages/be/b3/12d8cedc200100450d0266db98c2d0270699f77cdebac334c2ce63503b1d/google-hangouts-chat-bot-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ea0379f7c196e4d0d4b291d1a64f8dec", "sha256": "029ad033643892d7c613ee07214f3f14fc496a824c4fb5fa2545091d5c570b60" }, "downloads": -1, "filename": "google-hangouts-chat-bot-0.2.0.tar.gz", "has_sig": false, "md5_digest": "ea0379f7c196e4d0d4b291d1a64f8dec", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9443, "upload_time": "2019-11-27T21:01:14", "upload_time_iso_8601": "2019-11-27T21:01:14.680684Z", "url": "https://files.pythonhosted.org/packages/be/b3/12d8cedc200100450d0266db98c2d0270699f77cdebac334c2ce63503b1d/google-hangouts-chat-bot-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }