https://github.com/nicolastrres/slack-bot-wrapper
https://github.com/nicolastrres/slack-bot-wrapper
bot slack slack-bot
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nicolastrres/slack-bot-wrapper
- Owner: nicolastrres
- Created: 2017-04-02T14:13:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-05T14:12:25.000Z (about 9 years ago)
- Last Synced: 2025-11-27T16:35:13.979Z (7 months ago)
- Topics: bot, slack, slack-bot
- Language: Python
- Size: 25.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# slack-bot-wrapper
Allows to create Slack bots and add features to them very easily.
It uses the [python-slackclient](https://github.com/slackapi/python-slackclient) and creates a wrapper for it.
# Installation
` pip install slack-bot-wrapper `
# Example
```python
import os
from slackclient import SlackClient
from slack_bot import SlackClientWrapper
from slack_bot import SlackBot
def bye():
slack_wrapper.post_message(
channel='some-channel',
message='Bye! :slightly_smiling_face:',
as_user=True
)
def hello():
slack_wrapper.post_message(
channel='some-channel',
message='Hello! :smile:',
as_user=True
)
# Commands that the bot understand, it is a dict with the name of the command as key and the
# function that will be executed as value.
COMMAND_HANDLERS = {
'hello': hello,
'bye': bye
}
if __name__ == '__main__':
# First import the python-slackclient and instantiate it.
slack_client = SlackClient(token=os.environ.get('SLACK_BOT_TOKEN'))
# Instantiate the SlackClientWrapper with the slack client.
slack_wrapper = SlackClientWrapper(slack_lib=slack_client)
# Instantiate the slack bot sending the bot name, client wrapper and the commands
slack_bot = SlackBot(
bot_name='bot-name',
client=slack_wrapper,
commands_handlers=COMMAND_HANDLERS
)
# Start the slack bot, it allows the bot to start reading messages and interact with the users
slack_bot.start()
```
For a more complex examples take a look to the [examples folder](https://github.com/nicolastrres/slack-bot-wrapper/tree/master/examples).