{ "info": { "author": "Alex Tzonkov", "author_email": "alex.tzonkov@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "[![PyPI](https://badge.fury.io/py/mmpy-bot.svg)](https://pypi.org/project/mmpy-bot/)\n[![Travis-Ci](https://travis-ci.com/attzonko/mmpy_bot.svg?branch=master)](https://travis-ci.com/attzonko/mmpy_bot)\n[![Codacy](https://api.codacy.com/project/badge/grade/b06f3af1d8a04c6faa9a76a4ae3cb483)](https://www.codacy.com/app/attzonko/mmpy_bot)\n[![Maintainability](https://api.codeclimate.com/v1/badges/809c8d66aea982d9e3da/maintainability)](https://codeclimate.com/github/attzonko/mmpy_bot/maintainability)\n[![Python Support](https://img.shields.io/pypi/pyversions/mmpy-bot.svg)](https://pypi.org/project/mmpy-bot/)\n[![Mattermost](https://img.shields.io/badge/mattermost-4.0+-blue.svg)](http://www.mattermost.org)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://pypi.org/project/mmpy-bot/)\n\nDocumentation available at [Read the Docs](http://mmpy_bot.readthedocs.org/).\n\n\n## What is This\n\nA python based chat bot for [Mattermost](http://www.mattermost.org).\n\n## Features\n\n* Based on Mattermost [WebSocket API(V4.0.0)](https://api.mattermost.com)\n* Simple plugins mechanism\n* Messages can be handled concurrently\n* Automatically reconnect to Mattermost when connection is lost\n* Python3 Support\n\n\n## Compatibility\n\n| Mattermost | mmpy_bot |\n|------------------|:-----------:|\n| >= 4.0 | > 1.2.0 |\n| < 4.0 | unsupported |\n\n\n## Installation\n\n```\npip install mmpy_bot\n```\n\n## Usage\n\n### Registration\n\nFirst you need create the mattermost email/password for your bot.\n\nFor use all API(V4.0.0), you need add bot user to system admin group to avoid 403 error.\n\n### Configuration\n\nThen you need to configure the `BOT_URL`, `BOT_LOGIN`, `BOT_PASSWORD`, `BOT_TEAM` in a python module\n`mmpy_bot_settings.py`, which must be located in a python import path.\n\n\nmmpy_bot_settings.py:\n\n```python\nSSL_VERIFY = True # Whether to perform SSL cert verification\nBOT_URL = 'http:///api/v4' # with 'http://' and with '/api/v4' path. without trailing slash.\nBOT_LOGIN = ''\nBOT_PASSWORD = ''\nBOT_TOKEN = None # or '' if you have set bot personal access token.\nBOT_TEAM = '' # possible in lowercase\nWEBHOOK_ID = '' # otherwise the bot will attempt to create one\n```\n\nAlternatively, you can use the environment variable `MATTERMOST_BOT_URL`,\n`MATTERMOST_BOT_LOGIN`, `MATTERMOST_BOT_PASSWORD`, `MATTERMOST_BOT_TEAM`,\n`MATTERMOST_BOT_SSL_VERIFY`, `MATTERMOST_BOT_TOKEN`\n\nor `MATTERMOST_BOT_SETTINGS_MODULE` environment variable, which provide settings module\n\n```bash\nMATTERMOST_BOT_SETTINGS_MODULE=settings.bot_conf mmpy_bot\n```\n\n\n### Run the bot\n\nUse the built-in cli script and point to your custom settings file.\n\n```bash\nMATTERMOST_BOT_SETTINGS_MODULE=mmpy_bot_settings mmpy_bot\n```\n\nor you can create your own startup file. For example `run.py`:\n\n```python\nfrom mmpy_bot.bot import Bot\n\n\nif __name__ == \"__main__\":\n Bot().run()\n```\n\nNow you can talk to your bot in your mattermost client!\n\n\n\n## Attachment Support\n\n```python\nfrom mmpy_bot.bot import respond_to\n\n\n@respond_to('webapi')\ndef webapi_reply(message):\n attachments = [{\n 'fallback': 'Fallback text',\n 'author_name': 'Author',\n 'author_link': 'http://www.github.com',\n 'text': 'Some text here ...',\n 'color': '#59afe1'\n }]\n message.reply_webapi(\n 'Attachments example', attachments,\n username='Mattermost-Bot',\n icon_url='https://goo.gl/OF4DBq',\n )\n # Optional: Send message to specified channel\n # message.send_webapi('', attachments, channel_id=message.channel)\n```\n\n*Integrations must be allowed for non admins users.*\n\n\n## File Support\n\n```python\nfrom mmpy_bot.bot import respond_to\n\n\n@respond_to('files')\ndef message_with_file(message):\n # upload_file() can upload only one file at a time\n # If you have several files to upload, you need call this function several times.\n file = open('test.txt')\n result = message.upload_file(file)\n file.close()\n if 'file_infos' not in result:\n message.reply('upload file error')\n file_id = result['file_infos'][0]['id']\n # file_id need convert to array\n message.reply('hello', [file_id])\n```\n\n\n## Plugins\n\nA chat bot is meaningless unless you can extend/customize it to fit your own use cases.\n\nTo write a new plugin, simply create a function decorated by `mmpy_bot.bot.respond_to` or `mmpy_bot.bot.listen_to`:\n\n- A function decorated with `respond_to` is called when a message matching the pattern is sent to the bot (direct message or @botname in a channel/group chat)\n- A function decorated with `listen_to` is called when a message matching the pattern is sent on a channel/group chat (not directly sent to the bot)\n\n```python\nimport re\n\nfrom mmpy_bot.bot import listen_to\nfrom mmpy_bot.bot import respond_to\n\n\n@respond_to('hi', re.IGNORECASE)\ndef hi(message):\n message.reply('I can understand hi or HI!')\n\n\n@respond_to('I love you')\ndef love(message):\n message.reply('I love you too!')\n\n\n@listen_to('Can someone help me?')\ndef help_me(message):\n # Message is replied to the sender (prefixed with @user)\n message.reply('Yes, I can!')\n\n # Message is sent on the channel\n # message.send('I can help everybody!')\n```\n\nTo extract params from the message, you can use regular expression:\n```python\nfrom mmpy_bot.bot import respond_to\n\n\n@respond_to('Give me (.*)')\ndef give_me(message, something):\n message.reply('Here is %s' % something)\n```\n\nIf you would like to have a command like 'stats' and 'stats start_date end_date', you can create reg ex like so:\n\n```python\nfrom mmpy_bot.bot import respond_to\nimport re\n\n\n@respond_to('stat$', re.IGNORECASE)\n@respond_to('stat (.*) (.*)', re.IGNORECASE)\ndef stats(message, start_date=None, end_date=None):\n pass\n```\n\nIf you don't want to expose some bot commands to public, you can add `@allowed_users()` like so:\n\n```python\n@respond_to('^admin$')\n@allow_only_direct_message() #only trigger by direct message, remove this line if you want call this in channel\n@allowed_users('Your username or email address here')\ndef users_access(message):\n pass\n```\n\nAnd add the plugins module to `PLUGINS` list of mmpy_bot settings, e.g. mmpy_bot_settings.py:\n\n```python\nPLUGINS = [\n 'mmpy_bot.plugins',\n 'devops.plugins', # e.g. git submodule: domain:devops-plugins.git\n 'programmers.plugins', # e.g. python package: package_name.plugins\n 'frontend.plugins', # e.g. project tree: apps.bot.plugins\n]\n```\n*For example you can separate git repositories with plugins on your team.*\n\n\nIf you are migrating from `Slack` to the `Mattermost`, and previously you are used `SlackBot`,\nyou can use this battery without any problem. On most cases your plugins will be working properly\nif you are used standard API or with minimal modifications.\n\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/attzonko/mmpy_bot", "keywords": "chat bot mattermost", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "mmpy-bot", "package_url": "https://pypi.org/project/mmpy-bot/", "platform": "Any", "project_url": "https://pypi.org/project/mmpy-bot/", "project_urls": { "Homepage": "https://github.com/attzonko/mmpy_bot" }, "release_url": "https://pypi.org/project/mmpy-bot/1.3.4/", "requires_dist": [ "Sphinx (>=1.3.3)", "requests (>=2.20.0)", "schedule (>=0.5.0)", "six (>=1.10.0)", "websocket-client (>=0.35.0)" ], "requires_python": "", "summary": "A python based bot for Mattermost", "version": "1.3.4" }, "last_serial": 4724719, "releases": { "1.2.0": [ { "comment_text": "", "digests": { "md5": "c290a53ee9bffc38346e9841ecd79849", "sha256": "52fcecba05408f4c56f11cd659065d54e37658ecf4975286f9d766b8ef06e844" }, "downloads": -1, "filename": "mmpy_bot-1.2.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "c290a53ee9bffc38346e9841ecd79849", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 22691, "upload_time": "2018-05-31T17:36:54", "url": "https://files.pythonhosted.org/packages/75/61/73d272810d3327a02062dcc35ed2ee421bfe2714ea384f14c753e2f874f3/mmpy_bot-1.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3ad97f81d09d012a1c32b891cabe7d45", "sha256": "6526cd4fd67bc11b326de5d54253e983d11b8a47b96aa3b542ed38a9f6427cf9" }, "downloads": -1, "filename": "mmpy_bot-1.2.0.tar.gz", "has_sig": true, "md5_digest": "3ad97f81d09d012a1c32b891cabe7d45", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17044, "upload_time": "2018-05-31T17:36:38", "url": "https://files.pythonhosted.org/packages/61/d3/78da4d1fad5e9f7e664ba7e3273b6637f00149c7c9860f3f7a0e17621baf/mmpy_bot-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "248c6173d85d6c8f149c87b6cec68aa2", "sha256": "a90e09d6847b7f152b695abd10a8ba7ae9cf59bf5b25c24add8a72b632dc5474" }, "downloads": -1, "filename": "mmpy_bot-1.2.1-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "248c6173d85d6c8f149c87b6cec68aa2", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 23984, "upload_time": "2018-07-19T08:01:30", "url": "https://files.pythonhosted.org/packages/a0/e7/19190571ffa53e6a56a1a48d02140957b2582d03cfcc4c8385072a275047/mmpy_bot-1.2.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1ca0aee34fade1ee398afacb045d2f87", "sha256": "26ec54dffb18aae8ae887f56f3eadc5819c1da903fb147b910968298df62dde5" }, "downloads": -1, "filename": "mmpy_bot-1.2.1.tar.gz", "has_sig": true, "md5_digest": "1ca0aee34fade1ee398afacb045d2f87", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14890, "upload_time": "2018-07-19T08:01:15", "url": "https://files.pythonhosted.org/packages/e5/2d/833e84f9b3c16a8f3a5849fb593942a2af25d63901e3ea52508c2ace2e97/mmpy_bot-1.2.1.tar.gz" } ], "1.3.0": [ { "comment_text": "", "digests": { "md5": "6a140ed615588b5841e02b77d3abca38", "sha256": "c277200eb24f511f746a0e0a08469fa49e860ff9e12139dbf687aa804522ba84" }, "downloads": -1, "filename": "mmpy_bot-1.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6a140ed615588b5841e02b77d3abca38", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22630, "upload_time": "2018-08-29T06:37:48", "url": "https://files.pythonhosted.org/packages/e3/af/57c556fe1255e1c6c2322fa42ebdba3c7a95af542fc91b708a72b6a639bd/mmpy_bot-1.3.0-py2.py3-none-any.whl" } ], "1.3.2": [ { "comment_text": "", "digests": { "md5": "a58272c7101ff17991a60e05a01c932d", "sha256": "19938f7d16d56848850f3308f5824391b37b2569f84fb115add803d47fb8a528" }, "downloads": -1, "filename": "mmpy_bot-1.3.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a58272c7101ff17991a60e05a01c932d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22965, "upload_time": "2018-10-24T23:47:15", "url": "https://files.pythonhosted.org/packages/33/58/afcf7462af70ea78bfecadc882fe4ba1b381753a8e6d92a273282d519d57/mmpy_bot-1.3.2-py2.py3-none-any.whl" } ], "1.3.3": [ { "comment_text": "", "digests": { "md5": "7518a80ab90c24deb0b8691dc2bc8b37", "sha256": "be14a50d6e7c6cd52d461acc68ccd1bc787fbe8bec9ba7642fe9f4973d7c98d5" }, "downloads": -1, "filename": "mmpy_bot-1.3.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7518a80ab90c24deb0b8691dc2bc8b37", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22982, "upload_time": "2018-11-05T07:03:26", "url": "https://files.pythonhosted.org/packages/18/9c/37294e4468ed91112e1111622c56e684e3e5e4d94ba50f0620f79270fce7/mmpy_bot-1.3.3-py2.py3-none-any.whl" } ], "1.3.4": [ { "comment_text": "", "digests": { "md5": "07832ddafa0d07db04951d8533d0f2d1", "sha256": "e2867fa9b9b459874655987de884dba0781d736c2f58cc4d8c86bd48f89e805c" }, "downloads": -1, "filename": "mmpy_bot-1.3.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "07832ddafa0d07db04951d8533d0f2d1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 23177, "upload_time": "2019-01-22T07:08:30", "url": "https://files.pythonhosted.org/packages/a6/b4/ba2ede84e04fa30f13b72ebfbb2887722d637b74c719a68fae7f7b6f150e/mmpy_bot-1.3.4-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "07832ddafa0d07db04951d8533d0f2d1", "sha256": "e2867fa9b9b459874655987de884dba0781d736c2f58cc4d8c86bd48f89e805c" }, "downloads": -1, "filename": "mmpy_bot-1.3.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "07832ddafa0d07db04951d8533d0f2d1", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 23177, "upload_time": "2019-01-22T07:08:30", "url": "https://files.pythonhosted.org/packages/a6/b4/ba2ede84e04fa30f13b72ebfbb2887722d637b74c719a68fae7f7b6f150e/mmpy_bot-1.3.4-py2.py3-none-any.whl" } ] }