![]() ![]() To review the details for the Lambda function, choose Next, and then choose Create function.Type lambda-exec-role-for-lex, which is the role that you created for this Lambda function to assume. Leave the Handler set to index.handler, and then choose Choose an existing role.You need to create the gateway before you can set the API_GATEWAY_URL value, so leave that field blank for now. The Lambda function uses four environment variables.Because the Node.js application uses third-party modules, you can’t use the Lambda console editor to edit code.For the Lambda function, type LexTwilioIntegration, and for the Runtime environment, choose js 4.3.Leave the trigger empty, and then choose Next.Choose the Blank Function blueprint, and choose Next.Log in to the AWS Lambda console, and choose Create a Lambda function.Expand the Inline Policies section and create a new custom policy by pasting in this JSON: Search the list of roles to find the new role.Name this role lambda-exec-role-for-lex, and then choose Create role. On the next page, choose Next Step without selecting a policy (you’ll define a custom policy).In this case, that event is an HTTPS call to API Gateway made by Twilio.īefore diving into coding the Lambda function, you need to set up permissions. Lambda gives you the ability to run custom code based on an event. Lambda–the preprocessing layer between Amazon Lex and Twilio But first, you need to create your serverless application. We’ll return to the Twilio Console to configure the webhook that posts the SMS message to our serverless application. On the Twilio Console Dashboard, note your Twilio AUTH TOKEN. Make sure that your Twilio number has SMS capability turned on, and that you verify your own phone number with Twilio for testing. If you don’t already have a Twilio account, you can sign-up for a trial account, which includes a free phone number. Next, set up a Twilio SMS-enabled phone number where users can send SMS messages to interact with your bot. ![]() Let’s change that! Setting up an SMS-enabled Twilio phone number ![]() You now have a working bot, but it can’t communicate with anyone outside the console. After Amazon Lex builds the bot, test it in the console.Choose the BookTrip sample, note the name of the AWS Identity and Access Management (IAM) role, and choose Create.Log in to the Amazon Lex console, and choose Create in the Bots.For this example, use one of the example bots that are provided in the Amazon Lex console. An HTTPS response is sent to the Twilio endpoint, which relays the message to the user as an SMS text message.You can implement your own custom routing logic and send messages to different bots based on your own business rules. For the sake of brevity, I haven’t included custom logic in this example. The Lambda function runs your business logic and uses the PostText runtime API call to communicate with your chatbot(s).API Gateway optionally authenticates the request, and then passes the request parameters to a Lambda function.Based on your configuration, Twilio makes an API call to the HTTPS endpoint hosted by API Gateway.The end user sends an SMS text to your Twilio number.API Gateway provides the secure API endpoint for a Lambda function that implements your business logic.īefore diving into the details, let’s examine how messages flow between the end user and your bot: Going serverless means that you don’t have to worry about managing individual instances, and that you incur costs only for the resources that your application uses. Architecture and message flowįor this integration, I chose a serverless architecture that uses Amazon API Gateway and AWS Lambda to robustly and scalably integrate the Amazon Lex bot with the Twilio messaging service. For example, if you’re in an enterprise, you could use this solution to implement custom message routing to specialized bots developed by different business units.įor simpler uses cases, the built-in integration for Twilio in the Amazon Lex console might be a better option. This is useful if you want to incorporate Amazon Lex as another building block into your systems. The solution includes a serverless middle tier or a preprocessing layer “in front of” Amazon Lex. ![]() You can integrate any messaging service that provides the right APIs with Amazon Lex using the design pattern described in this post. In this post, I show how to integrate an Amazon Lex bot with an external messaging service by using Twilio Programmable SMS as the example service. But what if you want to connect to a messaging service that isn’t supported? Well, there’s an API for that–the Amazon Lex API. Amazon Lex offers built-in integration with Facebook, Slack and Twilio. Is your Amazon Lex chatbot ready to talk to the world? When it is, chances are that you’ll want it to be able to interact with as many users as possible. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |