def _receive(self, packet): mail = json.loads(packet['data']) ty = mail.pop('type', None) if ty is None: logger.info('Unknown Slack event: %s', packet['data']) return h = self._event_handlers.get(ty) if h is None: logger.info('Unknown Slack event: %s', packet['data']) return h(mail) self.deliver(ty, mail)
def _connect(self, mail): logger.info('%s connecting to Slack', ["Retry","Try"][self._retry==0]) if self._retry + 1 < len(SLACK_RESTART_WAITTIMES): self._retry += 1 info = self._api.request('rtm.start').get() self._env = { 'team': info['team'], 'users': {user['id']: user for user in info['users']}, 'channels': {chan['id']: chan for chan in info['channels']}, 'groups': {group['id']: group for group in info['groups']}, 'ims': {im['id']: im for im in info['ims']}, } self._ws = WebSocket(info['url']) # make sure to complete adding Slack as a consumer of the websocket # before start it. self._ws.request('ws:add_consumer', {'consumer': self}).wait(1) self._ws.send('ws:start')
def _hello(self, mail): logger.info('Successfully connected to %s\'s Slack', self._env['team']['name']) self._retry = 0