Package: simple-slack-bot
Simple Slack BotSimple Slack Bot makes writing your next Slack bot incredibly easy. By factoring out common functionality all Slack Bots require, you can focus on writing your business logic.InstallingPipRun:$ pip3 install simple_slack_botFrom SourceTo install, simply clone the source, which will allow you to import SimpleSlackBot.ConfigurationTo configure, set a single environment variableSLACK_BOT_TOKENwith your Slack Bot's API tokenFinding Your Slack Bot API TokenTo generate or locate your Slack Bot Token, visithttps://[YOUR SLACK TEAM NAME HERE].slack.com/apps/manage/custom-integrationsand clickBotsIf you already have a bot created, you should see it listed here, otherwise you should be able to clickAdd Configurationto create one.Once you have a bot find it listed in the configurations and click theEditicon. You'll be brought to a page that lists your API token. This is what you'll use with Simple Slack Bot.ExampleTo integrate with Simple Slack Bot, simply create an instance of it and register for notifications using a Python decorator.This can be seen with the following code below. Our Simple Slack Bot will reply to every message of "Ping", with "Pong", to every channel it's a part of:ping_pong.pyfromsimple_slack_bot.simple_slack_botimportSimpleSlackBotsimple_slack_bot=SimpleSlackBot(debug=True)@simple_slack_bot.register("message")defpong_callback(request):ifrequest.messageandrequest.message.lower()=="ping":request.write("Pong")defmain():simple_slack_bot.start()if__name__=="__main__":main()At this point, your callback functions will be executed every time Simple Slack Bot receives the appropriate event.A repo of this example Ping Pong Bot can be foundhere. Feel free to use it as a reference or fork it as a stating point!Debug ModeNote: Simple Slack Bot can be initialized with debug mode turned on, which will display all debug messages out to stdout and stderr.To enable this simply passdebug=Truewhen initializing Simple Slack Bot. As seen below:simple_slack_bot=SimpleSlackBot(debug=True)Additional Logging ControlIf you want more control on the routing of your logging, instead of passingdebug=Truewhen initializing Simple Slack Bot, you can configure the globalloggingvariable in your own application.An example:import logging
from simple_slack_bot.simple_slack_bot import SimpleSlackBot

dict_config = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level': 'INFO',
            'formatter': 'standard',
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['default'],
            'level': 'INFO',
            'propagate': True
        },
        'django.request': {
            'handlers': ['default'],
            'level': 'WARN',
            'propagate': False
        },
    }
}

simple_slack_bot = SimpleSlackBot()
logging.config.dictConfig(dict_config)Where you'd create your owndictConfigbased on your own needs.Supported EventsSimple Slack Bot handles all of the parsing and routing of Slack events. To be informed of new slack events, you must register a callback function with Simple Slack Bot for each event. All Slack Events are registered to and can be seenhere.TherequestObjectEach method you decorate in your Simple Slack Bot will need to take in arequest. The contents of therequestwill differ depending on the event(s) you register to.For each event you register for, take a look at the eventhere, as this is where the contents of the request will be defined.For convenience, I've added the following attributes to allrequestobjects:type- type of eventchannel- the channel from the underlying SlackEventNote: This can be an empty String. For example, this will be an empty String for the 'Hello' event.message- the received messageHelper Functions & Callbacks Making CallbacksOften times when writing a Slack Bot, you'll find yourself writing a few key functions that I found generic enough to include in Simple-Slack-Bot. The function names are pretty self explanatory but they are as follows:helper_write(channel, content)- Writes a message to the channel as the bothelper_get_public_channel_ids()- Gets all public channel idshelper_get_private_channel_ids()- Gets all private channel idshelper_get_user_ids()- Gets all user idshelper_get_users_in_channel(channel_id)- Gets all users in a given channelhelper_name_to_channel_id(name)- Converts a channel name to its respected channel idhelper_user_name_to_user_id(name)- Converts a user name to its respected user idhelper_channel_id_to_channel_name(channel_id)- Converts a channel id to its respected channel namehelper_user_id_to_user_name(user_id)- Converts a user id to its respected user nameTo gain access to these functions, simply call the appropriate function on your SimpleSlackBot instance.Writing More Advanced Slack BotsIf you have found that Simple Slack Bot does not provide everything you are looking for, you can gain access to the underlyingpython Slack ClientorSlackSocket object.Running Local Development VersionIf you want to run the local version of Simple Slack Bot and not the verison you downloaded through PyPi, you can run the following in theSimple-Slack-Botdirectory:python3 setup.py installand then import it as usualfrom simple_slack_bot.simple_slack_bot import SimpleSlackBot.You'll also have to install Simple Slack Bot's dependencies using PyPi. Arequirements.txtwill be kept up to date, along side thesetup.pyfor this use case and your convenience.Unit TestsTo run the unit test suite, execute$ make testTo generate code coverage of the unit test suite, execute:$ make test-and-generate-coverageSimple Slack BotsWe'll be maintaining a list of Simple Slack Bots here.If you have written a Simple Slack Bot, please contact me to have yours added!NameAuthorDescriptionPing Pong BotGreg HilstonPing Pong Bot was created to act as an example of how easy it is to create a bot using the open source Simple-Slack-Bot framework. Ping-Pong-Bot will look at every message sent to the channels that it is in, waiting for the case insensitive message "Ping". Once received Ping-Pong-Bot will write back to the very same channel "Pong".The Office BotGreg HilstonThe Office Bot will look at every message sent to the channels that,it is in, waiting for a mention of the name of a character in the show, The Office, specifically the US version. Once received, The-Office-Bot will write back a random line that this character had throughout the show, including lines from deleted scenes.Stan BotJahir FiquitivaStan Bot is a bot to help one with the SCRUM stand-up process.Dice BotGreg HilstonDice Bot is used to perform simple dice rollsDnD BotGreg HilstonD and D Bot is used record small D&D sessions that take place in Slack, by recording the in gmae chat to acsv