def react(self, channel, ts, emoji): return Slack.get_instance().api_call( 'reactions.add', name=emoji, channel=channel, timestamp=ts )
def open_im(self, user): response = Slack.get_instance().api_call( 'im.open', user=user ) return response['channel']['id']
def _upload_file_reply( self, msg, filename, content, in_thread=True, initial_comment=None, filetype=None, ): kwargs = {} kwargs["method"] = "files.upload" kwargs["content"] = content kwargs["filename"] = filename kwargs["title"] = filename kwargs["channels"] = [msg.channel.id] if filetype: kwargs["filetype"] = filetype if initial_comment: kwargs["initial_comment"] = initial_comment if in_thread and msg.thread_ts: kwargs["thread_ts"] = msg.thread_ts instance = Slack.get_instance() response = instance.api_call(**kwargs) send_text = "Uploaded {filename!r} to channel {channel} in thread {thread}" send_text = send_text.format( filename=filename, channel=msg.channel.id, thread=kwargs.get("thread_ts", None), ) text.announce(send_text) return response
def send_dm_webapi(self, user, text, attachments=None): u = self.users.find(user) dm_channel = self.open_im(u.id) return Slack.get_instance().api_call('chat.postMessage', channel=dm_channel, text=text, attachments=attachments, as_user=True)
def send_webapi(self, channel, text, attachments=None, thread_ts=None, ephemeral_user=None): method = 'chat.postMessage' # This is the only way to conditionally add thread_ts kwargs = { 'channel': channel, 'text': text, 'attachments': attachments, 'as_user': True } if ephemeral_user: method = 'chat.postEphemeral' kwargs['user'] = ephemeral_user else: if thread_ts: kwargs['thread_ts'] = thread_ts return Slack.get_instance().api_call( method, **kwargs )
def channels(self): return Slack.get_instance().server.channels
def users(self): return Slack.get_instance().server.users
def send(self, channel, text, thread_ts=None): Slack.get_instance().rtm_send_message(channel, text, thread_ts)
def retrieve_bot_info(): return Slack.get_instance().server.login_data['self']
def scheduled_messages(self): response = Slack.get_instance().api_call('chat.scheduledMessages.list') return response
def read_group_topic_webapi(self, channel): method = 'groups.info' kwargs = {'channel': channel, 'as_user': True} return Slack.get_instance().api_call(method, **kwargs)
def set_group_topic_webapi(self, channel, text): method = 'groups.setTopic' kwargs = {'channel': channel, 'topic': text, 'as_user': True} return Slack.get_instance().api_call(method, **kwargs)