Skip to content

Commit

Permalink
Import beepboop package and provide integration to support multi-team…
Browse files Browse the repository at this point in the history
… bot deployment.
  • Loading branch information
randompi committed Mar 30, 2016
1 parent 8fbf77b commit da6ba4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 11 additions & 3 deletions bot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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({})
9 changes: 7 additions & 2 deletions bot/slack_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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():
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
beepboop==0.1.1
docutils==0.12
lockfile==0.12.2
python-daemon==2.1.1
Expand Down

0 comments on commit da6ba4c

Please sign in to comment.