When working with Lex, we have an intent and slot content in JSON like files and we have controller.py which does most of the work for eliciting slot, delegating or fulfilling intent. When we are building Alexa or Lex bot, it's a good idea to control main content from one place.
To achieve this, we can divide the concern into three different Lambdas - Core Controller, Lex Application Renderer, and Alexa Renderer. This can further be divided based on the device we are targeting - Echo Show or Dot. This way, core services - authentication, authorization, translation etc will be handled at one central place.
Core Controller
This Lambda receives intent and slots, and decides what should be the response content and what should be the next step (elicit slot). This is what the Lambda will look like:
This will return the content of response - text, images, videos. We should have these on S3 and provide pre-signed URLs in response.
Lex Application Renderer
This Lambda gets requests from Lex, passes on to the core controller, and then builds the required response for mobile/web application. All the templating part for mobile/web application is being done here. I have created a basic web-app which can be used with any Lex bot.
Alexa Renderer
This Lambda will be configured in skill and will receive the request from Alexa. Then it will call the core controller and get content. Now, this Lambda will do all the Alexa templating.
Example
If core controller returns:
Then Alexa Renderer Lambda will process this and return Alexa device's expected response.
<action> tag generates links in Echo Show which user can click and it will send the "Display.ElementSelected" event back to Lambda.
And mobile/web app renderer can send something below, which then mobile/web app can handle to show to the user. Check the web widget here.
We have to have some mapping between them like - 'ui_type' picker maps with BodyTemplate1 and buttons in different Renderers.
Interested in more how-tos around AWS services? Check out:
Our Services
Customer Experience Management
- Content Management
- Marketing Automation
- Mobile Application Development
- Drupal Support and Maintanence
Enterprise Modernization, Platforms & Cloud
- Modernization Strategy
- API Management & Developer Portals
- Hybrid Cloud & Cloud Native Platforms
- Site Reliability Engineering