【问题标题】:Slack bot | check message reactions松弛机器人 |检查消息反应
【发布时间】:2020-07-10 04:31:53
【问题描述】:

我目前正在开发一个 slack 机器人。 一旦请求的任务完成,这将要求用户添加对消息的反应。 但是,我不知道如何执行此任务,并且我的 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.")

如果有人可以帮助我。

【问题讨论】:

    标签: python slack slack-api


    【解决方案1】:

    您将需要使用reactions.get 方法。您只需提供您想要获得响应的消息的timestamp。

    您的代码看起来只是在发布一条消息。如果您想在用户对消息做出反应时做某事,您需要订阅message 事件。这意味着拥有一个正在运行的服务(使用事件 API 将其发布给您,或者使用 RTM API 订阅)

    【讨论】:

      猜你喜欢
      • 2018-03-19
      • 2016-10-27
      • 2017-03-02
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      相关资源
      最近更新 更多