带pythonrtmbot的Slack RTM:建立短链接

2024-05-26 21:52:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为python-rtmbot开发一个插件,并尝试从该插件输出短链接,如下所示: <http://google.com|test>。我的目标是在Slack中显示这个:test-一个可单击的链接,而不显示完整的URL。在

但是,Slack bot只显示原始文本<http://google.com|test>。我修改了文件中名为output()的函数rtmbot.py

def output(self):
    for plugin in self.bot_plugins:
        limiter = False
        for output in plugin.do_output():
            channel = self.slack_client.server.channels.find(output[0])
            if channel != None and output[1] != None:
                if limiter == True:
                    time.sleep(.1)
                    limiter = False
                message = output[1].encode('ascii','ignore') + "<http://google.com|test>"
                #channel.send_message("{}".format(message))
                self.slack_client.api_call('chat.postMessage', channel=output[0], text=message, as_user=True)
                limiter = True

而不是使用channel.send_消息(),我改为使用self.slack_客户端.api_call(),它是SlackClient包中SlackClient的一个实例。链接现在已正确显示,但显示时间较长(输出速度较慢)。在

有没有办法仍然使用channel.send_消息()具有短链路能力?欢迎有任何其他想法/建议。在


Tags: testselfcom插件sendtruehttpmessage

热门问题