From da6ba4c9d7ffb7d7c6ffe65d598dbaa38fab916f Mon Sep 17 00:00:00 2001 From: Randall Barnhart Date: Wed, 30 Mar 2016 16:49:53 -0600 Subject: [PATCH] Import beepboop package and provide integration to support multi-team bot deployment. --- bot/app.py | 14 +++++++++++--- bot/slack_bot.py | 9 +++++++-- requirements.txt | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bot/app.py b/bot/app.py index 337981b..ab9bd25 100755 --- a/bot/app.py +++ b/bot/app.py @@ -3,7 +3,11 @@ import logging import os +from beepboop import resourcer +from beepboop import bot_manager + from slack_bot import SlackBot +from slack_bot import spawn_bot logger = logging.getLogger(__name__) @@ -19,6 +23,10 @@ if slack_token == "": logging.info("SLACK_TOKEN env var not set, expecting token to be provided by Resourcer events") slack_token = None - - bot = SlackBot(slack_token) - bot.start({}) + botManager = bot_manager.BotManager(spawn_bot) + res = resourcer.Resourcer(botManager) + res.start() + else: + # only want to run a single instance of the bot in dev mode + bot = SlackBot(slack_token) + bot.start({}) diff --git a/bot/slack_bot.py b/bot/slack_bot.py index bde8fbb..75bc991 100644 --- a/bot/slack_bot.py +++ b/bot/slack_bot.py @@ -9,6 +9,10 @@ logger = logging.getLogger(__name__) +def spawn_bot(): + return SlackBot() + + class SlackBot(object): def __init__(self, token=None): """Creates Slacker Web and RTM clients with API Bot User token. @@ -29,8 +33,9 @@ def start(self, resource): Args: resource (dict of Resource JSON): See payload here - http://linktoresourcejson """ - if 'SlackBotAccessToken' in resource: - res_access_token = resource['SlackBotAccessToken'] + logger.debug('Starting bot for resource: {}'.format(resource)) + if 'resource' in resource and 'SlackBotAccessToken' in resource['resource']: + res_access_token = resource['resource']['SlackBotAccessToken'] self.clients = SlackClients(res_access_token) if self.clients.rtm.rtm_connect(): diff --git a/requirements.txt b/requirements.txt index f447a5f..9def97a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +beepboop==0.1.1 docutils==0.12 lockfile==0.12.2 python-daemon==2.1.1