Request & Response Interceptors Part 2

Tom Berwick
Alexa Skills Dev
Published in
2 min readApr 3, 2020
Photo by Kevin Ku on Unsplash

I wanted to follow up on my last post around request and response interceptors with some more practical uses for them.

The Alexa Api/SDKs offer a number of great utility methods to help you do things, such as schedule reminders, get info about a persons timezone and many other useful resources.

You’ll quickly find though, that for things like reminders etc. you might make use of the same functionality to retrieve information in a number of intents. Of course following the principles of DRY you can move this common code to its own function, but you can also make use of the request interceptor to do some of the legwork for you.

For instance, you could capture the users locale in your request interceptor and then store it in your sessionAttributes to make it available throughout the rest of the request/response lifecycle.

Of course don’t forget to add the ApiClient to your custom handler as shown at the bottom of the example.

Another key thing to remember is that both the request and response handler have access to the handlerInput, so you don’t technically have to run your code on every request. I was contacted by someone asking if setting persistentAttributes on every request has an effect on a skills response time. I haven’t noticed anything as of yet on my skills, but the responseInterceptor could easily be changed to check if the current intent was a “SessionEndedRequest” and then only save the persistent attributes on those instances.

If anyone has any questions or ideas for a future post, please reach out via my Facebook group https://www.facebook.com/groups/alexaskillsdevelopers

I’m also considering branching out into Twitch/Youtube to do some code alongs. Please let me know on the Facebook group or the comments if you think this would be useful.

Finally, it would be great if you could check out my latest sci-fi game Last Flight of the Icarus on your Alexa devices.

--

--

Tom Berwick
Alexa Skills Dev

Mobile App, game and full stack developer. Constantly trying to learn new things and dabble in growth hacking