As we have gone through Lex journey, 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 and Lex bot both a use case it's a better idea to controller main content from one place. To Achieve this, we can divide the concern into 3 different lambdas - Core Controller, Lex Application Renderer, 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.
This lambda receives intent and slots and decides what should be response content and what should be next step (Elicit slot). This lambda will look like:
This will return the content of response - text, images, videos (we should have these s3 and provide pre-signed URLs in response).
Lex Application Renderer
This lambda gets requests from Lex, passes on 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, have a look - https://github.com/crazyrohila/lex-web-app
This lambda will be configured in skill and will receive the request from Alexa. Then It will call the core controller and gets content. Now, this lambda will do all the Alexa templating.
If core controller returns:
Then Alexa Renderer lambda will process this and return Alexa device's expected response. <action> tag generate links in echo show which user can click and it will send 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 https://github.com/crazyrohila/lex-web-app for web widget].
We have to have some mapping between them like - 'ui_type' picker maps with BodyTemplate1 and buttons in different Renderers.