Answer a Question With Choices

Now let’s get the bot to respond to the customer with a question. A bot can send questions with a selection of answers to choose from. The customer then selects the answer by clicking it in the widget or by typing it as a text message. The widget type, which is either buttons or menu, determines the look of the answers in the client. This response has the choices message type. The messages object in this response payload has the ChoicesResponseMessage schema in the API reference doc.

In this example, the bot asks what language (English, Spanish, or Japanese) the customer wants to communicate in.

Let’s say the customer answers by clicking the “Spanish” button. In this case, the request uses the choice message type.

When the customer answers by clicking a button, the request contains either the choiceId or choiceIndex of the answer.

If the customer types an answer, use the text message type in the request body. If a valid answer isn’t provided to the choice question, the bot sends the question again. Here’s an example of a customer that types “Español” as their answer.