Working with Dynamic Responses

Learn what Dynamic Responses are and how to use them to manage application state.

Asif
Houndify
4 min readFeb 27, 2018

--

Some Houndify domains may return more than one response and require clients to choose between those responses. These domains are using a feature called Dynamic Responses. In this tutorial, we’ll talk about what Dynamic Responses are, why they are useful, and how to leverage them in your client.

Checking if a domain uses Dynamic Responses

You can determine if a domain is using Dynamic Responses by checking the Client Integration Requirement section on the domain’s documentation page.

Additionally, the Try API tool will warn about this requirement and will display both default and success responses.

Home Automation Domain returns dynamic responses on the Try API Widget.

Let’s dig deeper into how Dynamic Responses work by looking at the SMS domain as an example.

Example: Dynamic Responses in the SMS Domain

The SMS domain allows composing text messages to your uploaded contacts using conversation state and dynamic responses. Let’s walk through how this works.

  1. Assume that we have uploaded the following contact information. The Syncing User Data tutorial covers how to upload JSON contact such as the one below.

2. If we make a query “Text Bob” we will get an SMSCommand JSON result. It will contain NativeData field of type ComposeSMSCommandNativeData. It will also contain the information required for sending the SMS.

Apart from NativeData, the result will contain several dynamic responses. You can choose which response to use based on the state of your client.

  • ClientActionSucceededResult: Use this if the SMS was sent correctly.
  • ClientActionFailedResult: Use this if the SMS failed to send.
  • NoSMSAppResult: Use this if there is no SMS application available on the client.
  • ComposeSMSResult: Use this if you are missing the body of the SMS, and have only received the sender’s information.
  • DisambiguationSMSResult: Use this if the query cannot be fulfilled because the user didn’t provide enough information to uniquely specify the needed information.
  • ExitSMSResult : Use this to

Since we are missing the body of the text, we should choose ComposeSMSResult and continue the conversation. We pick the ConversationState for this dynamic response and send it with the next query that contains the text message.

3. After we send “Where are you?” as a follow up query we will get similar set of dynamic responses, but ComposeSMSResult will now respond with “Would you like to send, review, continue, or cancel?”. NativeData will contain all the data we need to send the text.

4. If we reply with query “Send it” and ConversationState from ComposeSMSResult, NativeData will contain flag SendSMSNow: true.

Now we can send the SMS. Note that it is a client’s responsibility to send the actual text and choose the correct dynamic response based on the status.

Example script for testing SMS domain using Houndify Python SDK

We hope that this tutorial helps you understand how Dynamic Responses work. Leave a comment if you have any questions.

--

--