如何确定通过交互式消息向用户提示了哪个问题?

How to determine which question was prompted to the user with interactive messages?

我尝试了运行其中一个使用 slacks api 的演示,专门用于交互式消息。

我想执行以下操作:

  1. 向用户提问 1
  2. 向用户提问 2
  3. 问用户问题 3

我不明白的是,我怎么知道用户何时在回答特定问题?

在我的数据库中说我有一个问题 table,我在其中存储问题 #1、#2 和 #3 等

当我收到用户的回复时,根据 question_id 我将触发下一个问题。

我如何准确知道互动消息来自哪个问题?有没有办法让我在有效负载中获取 question_id?

确定用户回答了哪些交互式消息的标准方法是使用 callback_id。您可以为包含交互式消息(一组按钮、菜单等)的每个附件指定它,它将包含在对您的应用程序的响应请求中。

这是 documentationcallback_id 的评价:

The provided string will act as a unique identifier for the collection of buttons within the attachment. It will be sent back to your message button action URL with each invoked action. This field is required when the attachment contains message buttons. It is key to identifying the interaction you're working with.

如果您有多个按钮,每个按钮都有自己的名称,您可以使用它来识别单击了哪个按钮(结合 callback_id)。

如果您需要存储更多数据,可以使用 。有了它,您可以将 question_id 直接存储在按钮的 value 属性 中(例如 JSON 字符串)。