示例#1
0
 def react(self, channel, ts, emoji):
     return Slack.get_instance().api_call(
         'reactions.add',
         name=emoji,
         channel=channel,
         timestamp=ts
     )
示例#2
0
    def open_im(self, user):
        response = Slack.get_instance().api_call(
            'im.open',
            user=user
        )

        return response['channel']['id']
示例#3
0
 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
示例#4
0
    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)
示例#5
0
    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
        )
示例#6
0
 def channels(self):
     return Slack.get_instance().server.channels
示例#7
0
 def users(self):
     return Slack.get_instance().server.users
示例#8
0
 def send(self, channel, text, thread_ts=None):
     Slack.get_instance().rtm_send_message(channel, text, thread_ts)
示例#9
0
 def retrieve_bot_info():
     return Slack.get_instance().server.login_data['self']
示例#10
0
    def scheduled_messages(self):
        response = Slack.get_instance().api_call('chat.scheduledMessages.list')

        return response
示例#11
0
    def read_group_topic_webapi(self, channel):
        method = 'groups.info'

        kwargs = {'channel': channel, 'as_user': True}

        return Slack.get_instance().api_call(method, **kwargs)
示例#12
0
    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)