python - 松弛机器人 | 检查消息反应
问题描述
我目前正在开发一个松弛机器人。一旦请求的任务完成,这将要求用户添加对消息的反应。但是,我不知道如何执行此任务,并且我的 api 研究没有成功。我确实发现了resions.get 和reactions.list,但它似乎不是正确的解决方案。
这是我的代码:
import os
from slack import WebClient
from slack.errors import SlackApiError
import time
import datetime
from datetime import date
from dateutil.relativedelta import relativedelta, MO
client = WebClient(token=os.environ['SLACK_KEY'])
attachments = [{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello ! Il est temps de remplir le formulaire d'absences.\n\n*Merci de suivre les instructions ci-dessous.*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":round_pushpin: *<www.youtube.com|Clique ici pour te rendre sur la fiche d'absences.>* \nSurtout n'oublie pas de réagir avec :heavy_check_mark: afin d'indiquer que c'est bien fait."
}
}
]
}]
today = date.today()
def last_monday_of_month(any_day):
next_month = any_day.replace(day=28) + datetime.timedelta(days=4) # this will never fail
last_day = next_month - datetime.timedelta(days=next_month.day)
return last_day + relativedelta(weekday=MO(-2))
last_monday_of_month(date.today())
if today == last_monday_of_month(date.today()):
client.chat_postMessage(channel='starterbot', text="", attachments=attachments)
print("Success.")
else:
print("Error.")
如果有人可以帮助我。
解决方案
你会想要使用reactions.get方法。您只需提供timestamp
您想要获得反应的消息。
您的代码看起来就像您只是在发布一条消息。如果您想在用户对消息做出反应时做某事,您需要订阅消息事件。这意味着拥有一个正在运行的服务(使用事件 API 将其发布给您,或者使用 RTM API 订阅)
推荐阅读
- android - 如何从 sqlite Android 获取 id
- kubernetes - Kubernetes - 这是什么意思
用于服务描述中的端口 - apache - Apache2 卸载问题
- java - 如何在运行时将资源注册到类加载器?
- python-3.x - 带有日历的 Telegram Bot 配置文件
- matplotlib - 如何从networkx中提取特定社区而忽略其他社区?
- android - 如何为 kotlin 数据类创建单元测试用例
- c# - 多个 ListBox 绑定相同 SelectedItem 属性的问题
- c# - 从数据库中创建一个选择框列表并将其显示在 asp.net mvc 的视图中
- ios - 如何在我的 Swift 应用程序中打开外部文件(epub 文件)