设计 Slackbot 服务来发送自动消息

Design Slackbot service to send automated messages

第一次写slack bot,不知道怎么设计。

该机器人应该可用并立即响应最终用户的消息。

问题是我需要该机器人还会向注册用户发送带有自动化结果的日程安排消息。

用例示例:

A user sends a message to the bot and registered to a service that will check for changes in X. On a specific interval, my backend will call an automation that checks for those changes and will send a message to the user with the results.

这种情况的最佳做法是什么?

这是一个基本的大纲。

1.基本设置

  • 带有机器人用户的 Slack 应用程序
  • 数据库
  • 调度程序(例如本地 CRON 服务,或类似 cron-job.org 的 web-cron)

2。报名

  • 使用Events API to listen to messages from users send via mention (app_mention) or direct message (message.im)
  • 您的应用需要将从每个用户收到的 "registration" 存储在数据库中
  • 如果需要,直接响应用户请求 chat.postMessage

3。预定回复

  • 调度程序调用您的应用程序

  • 您的应用程序检查响应是否通过数据库查询到期

  • 如果是:应用程序通过 chat.postMessage 向用户发送响应(但由于速率限制,每秒不超过一条消息)