{"id":27170985,"url":"https://github.com/o920909/slack-bot","last_synced_at":"2025-04-09T08:22:04.347Z","repository":{"id":284564921,"uuid":"951331281","full_name":"o920909/slack-bot","owner":"o920909","description":"slack bot - real time messaging api, simple plugins mechanism, message can be handled concurrently, automatically reconnect to slack when connection is lost, full-fledged functional tests.","archived":false,"fork":false,"pushed_at":"2025-03-19T14:11:52.000Z","size":268,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T02:41:48.671Z","etag":null,"topics":["bot","messaging","plugin","real-time","slack"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/o920909.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-19T14:10:41.000Z","updated_at":"2025-03-19T14:12:29.000Z","dependencies_parsed_at":"2025-03-26T14:53:44.313Z","dependency_job_id":"d6395dc9-427c-4cfd-a216-6101e961e9d4","html_url":"https://github.com/o920909/slack-bot","commit_stats":null,"previous_names":["longzhang920909/slack-bot","o920909/slack-bot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o920909%2Fslack-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o920909%2Fslack-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o920909%2Fslack-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o920909%2Fslack-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o920909","download_url":"https://codeload.github.com/o920909/slack-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248000142,"owners_count":21031112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","messaging","plugin","real-time","slack"],"created_at":"2025-04-09T08:22:03.717Z","updated_at":"2025-04-09T08:22:04.317Z","avatar_url":"https://github.com/o920909.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI](https://badge.fury.io/py/slackbot.svg)](https://pypi.python.org/pypi/slackbot) [![Build Status](https://secure.travis-ci.org/lins05/slackbot.svg?branch=master)](http://travis-ci.org/lins05/slackbot)\n\nA chat bot for [Slack](https://slack.com) inspired by [llimllib/limbo](https://github.com/llimllib/limbo) and [will](https://github.com/skoczen/will).\n\n## Features\n\n* Based on slack [Real Time Messaging API](https://api.slack.com/rtm)\n* Simple plugins mechanism\n* Messages can be handled concurrently\n* Automatically reconnect to slack when connection is lost\n* [Full-fledged functional tests](tests/functional/test_functional.py)\n\n## Installation\n\n\n```\npip install slackbot\n```\n\n## Usage\n\n### Generate the slack api token\n\nFirst you need to get the slack api token for your bot. You have two options:\n\n1. If you use a [bot user integration](https://api.slack.com/bot-users) of slack, you can get the api token on the integration page.\n2. If you use a real slack user, you can generate an api token on [slack web api page](https://api.slack.com/web).\n\n\n### Configure the bot\nFirst create a `slackbot_settings.py` and a `run.py` in your own instance of slackbot.\n\n##### Configure the api token\n\nThen you need to configure the `API_TOKEN` in a python module `slackbot_settings.py`, which must be located in a python import path. This will be automatically imported by the bot.\n\nslackbot_settings.py:\n\n```python\nAPI_TOKEN = \"\u003cyour-api-token\u003e\"\n```\n\nAlternatively, you can use the environment variable `SLACKBOT_API_TOKEN`.\n\n##### Run the bot\n\n```python\nfrom slackbot.bot import Bot\ndef main():\n    bot = Bot()\n    bot.run()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n##### Configure the default answer\n\nAdd a DEFAULT_REPLY to `slackbot_settings.py`:\n```python\nDEFAULT_REPLY = \"Sorry but I didn't understand you\"\n```\n\n##### Configure the docs answer\n\nThe `message` attribute passed to [your custom plugins](#create-plugins) has an special function `message.docs_reply()` that will parse all the plugins available and return the Docs in each of them.\n\n##### Send all tracebacks directly to a channel, private channel, or user\nSet `ERRORS_TO` in `slackbot_settings.py` to the desired recipient. It can be any channel, private channel, or user. Note that the bot must already be in the channel. If a user is specified, ensure that they have sent at least one DM to the bot first.\n\n```python\nERRORS_TO = 'some_channel'\n# or...\nERRORS_TO = 'username'\n```\n\n##### Configure the plugins\n\nAdd [your plugin modules](#create-plugins) to a `PLUGINS` list in `slackbot_settings.py`:\n\n```python\nPLUGINS = [\n    'slackbot.plugins',\n    'mybot.plugins',\n]\n```\n\nNow you can talk to your bot in your slack client!\n\n### [Attachment Support](https://api.slack.com/docs/attachments)\n\n```python\nfrom slackbot.bot import respond_to\nimport re\nimport json\n\n\n@respond_to('github', re.IGNORECASE)\ndef github(message):\n    attachments = [\n    {\n        'fallback': 'Fallback text',\n        'author_name': 'Author',\n        'author_link': 'http://www.github.com',\n        'text': 'Some text',\n        'color': '#59afe1'\n    }]\n    message.send_webapi('', json.dumps(attachments))\n```\n\n## Create 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, simplely create a function decorated by `slackbot.bot.respond_to` or `slackbot.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/private channel chat)\n- A function decorated with `listen_to` is called when a message matching the pattern is sent on a channel/private channel chat (not directly sent to the bot)\n\n```python\nfrom slackbot.bot import respond_to\nfrom slackbot.bot import listen_to\nimport re\n\n@respond_to('hi', re.IGNORECASE)\ndef hi(message):\n    message.reply('I can understand hi or HI!')\n    # react with thumb up emoji\n    message.react('+1')\n\n@respond_to('I love you')\ndef love(message):\n    message.reply('I love you too!')\n\n@listen_to('Can someone help me?')\ndef help(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    # Start a thread on the original message\n    message.reply(\"Here's a threaded reply\", in_thread=True)\n```\n\nTo extract params from the message, you can use regular expression:\n```python\nfrom slackbot.bot import respond_to\n\n@respond_to('Give me (.*)')\ndef giveme(message, something):\n    message.reply('Here is {}'.format(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 slackbot.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```\n\n\nAnd add the plugins module to `PLUGINS` list of slackbot settings, e.g. slackbot_settings.py:\n\n```python\nPLUGINS = [\n    'slackbot.plugins',\n    'mybot.plugins',\n]\n```\n\n## The `@default_reply` decorator\n\n*Added in slackbot 0.4.1*\n\nBesides specifying `DEFAULT_REPLY` in `slackbot_settings.py`, you can also decorate a function with the `@default_reply` decorator to make it the default reply handler, which is more handy.\n\n```python\n@default_reply\ndef my_default_handler(message):\n    message.reply('...')\n```\n\nHere is another variant of the decorator:\n\n```python\n@default_reply(r'hello.*)')\ndef my_default_handler(message):\n    message.reply('...')\n```\n\nThe above default handler would only handle the messages which must (1) match the specified pattern and (2) can't be handled by any other registered handler.\n\n## List of third party plugins\n\nYou can find a list of the available third party plugins on [this page](https://github.com/lins05/slackbot/wiki/Plugins).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo920909%2Fslack-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo920909%2Fslack-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo920909%2Fslack-bot/lists"}