concept response in category alexa

appears as: responses, response, The response, response, responses, A response, The responses
Voice Applications for Alexa and Google Assistant

This is an excerpt from Manning's book Voice Applications for Alexa and Google Assistant.

IVR systems are designed for a tiny pool of choices and responses. Their ultimate goal is to get the caller to follow a decision tree to the desired outcome.

Any time you rely on implicit context, consider whether the user will know what the response is about. If the new request comes shortly after the previous one (within 15 seconds) or if the answer will otherwise make clear what the assumption was, you could probably be less clear and the user will understand. Otherwise, be explicit in your response and state the assumptions.

Any actions that are shared among the handlers could be done in the parts of the flow that are common to all handlers. These commonalities are when the request comes in and when the response heads out.

Figure 6.3 Flow of data inside the Name Info skill flow for SpellingIntent, with request and response interceptors

c06_03.eps

Interceptors, seen in figure 6.3, change the information flow to either take in the request before it hits the handler, or take in the response before it’s sent back to Alexa. By introducing these extra steps, the skill can prepare data or call methods that need to be shared across handlers. On the back side, the skill can perform any closing tasks or clean up before the invocation ends. For example, the request interceptor could introduce logging or prepare localization. The response interceptor could be used to centralize the code to save persistent data.

Listing 6.9 Saving before sending a response (./lambda/custom/index.json)
const SavePersistenceInterceptor = {
  async process(handlerInput, response) {    #1  
    try {
      await handlerInput.attributesManager.savePersistentAttributes();
    } catch (error) {
      throw Error(error);
    }
  }
};

...
exports.handler = Alexa.SkillBuilders.standard()
  .addRequestHandlers(
    ...
  )
  .addResponseInterceptors(SavePersistenceInterceptor)    #2  
  ...
  .lambda();

#1   Arguments are the request data and the assembled response.
#2   The interceptor is registered on the skill builder.

We can save the attributes immediately before we send the response because the fulfillment does not need to save the persistent attributes inside each of the handlers. We can store the data in memory in an object first, which is what we do when setting attributes. The only requirement is that we must send that information to the data store before sending the response. That’s because sending a response means the function’s role in that step in the conversation is over.

As we are required to send the data away only before we send the response, we do not need to distribute that action across different handlers and can simply set the data without saving it.