1

I tried running one of the demos using slacks apis, specifically for interactive messages.

I want to do the following:

  1. ask the user question 1
  2. ask the user question 2
  3. ask the user question 3

What I don't understand is how do I know when the user is responding to a particular question?

Say in my database I have a questions table, where I store question #1, #2 and #3 etc.

When I get a response from a user, depending on the question_id I will then trigger the next question.

How do I know exactly which question the interactive message originated from? is there a way for me to get the question_id in the payload?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

1

The standard approach to determine which of your interactive messages the user answered is to use callback_id. You can specify it for each each attachment containing an interactive message (a set of buttons, a menu, etc.) and it will be included in the response request to your app.

Here is what the documentation says about the callback_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.

If you have multiple buttons each will have its own name, which you can use to identify which button was clicked (in combination with the callback_id).

If you need to store more data you can use this hack. With that you could store your question_id directly in the value property of a button (e.g. as JSON string).

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114