slack bot 回复消息并提及 [英] slack bot respond to messages with a mention

查看:43
本文介绍了slack bot 回复消息并提及的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 slack bot,可以响应以特定字符串开头的消息.我更喜欢机器人只响应提到机器人的消息.我正在使用 slackclient 并通过以下方式获取消息:

I have a simple slack bot that can respond to messages that start with a specific string. What I would prefer is that the bot only responds to messages that have a mention of the bot. I'm using slackclient and getting messages via:

new_evts = sc.rtm_read()

我可以在消息中看到我的 client_id,但搜索消息字符串似乎不是正确的方法.

I can see the my client_id in the message but searching message stings doesn't seem to be the right approach.

u'text': u'<@U0TP3B7HU>: test message'

必须有一种更宽松的方式来处理提及的消息.我在 Slack API 中缺少什么?

There has to be a more slack-onic way of handling messages with mentions. What am I missing in the Slack API?

推荐答案

我找到了一个库,它提供了一种响应提及的方法.库提供了一种机制,用于指定当消息针对特定用户时要调用的函数.

I found a library that provides a way to respond to mentions. This library provides a mechanism to designate a function to be called when a message is directed at a specific user.

@respond_to('github', re.IGNORECASE)定义 github():...

我真的不喜欢正则表达式代码并且不得不搜索每个帖子.这是一种更简单的方法来处理对消息中的 DM 或 @references 的响应.

I really didn't like the regular expression code and having to search every posted. This is a simpler way to handle responding to DMs or @references in messages.

这篇关于slack bot 回复消息并提及的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆