How to Upload a Bot to Aws
Creating A chatbot with Amazon Lex AWS Lambda and Integrate with Facebook Messenger.
Sourav Sutradhar
Sourav Sutradhar
System Software Engineer at American Megatrends International.
In this article, yous volition create a bot to handle pizza orders
What is Amazon Lex?
Amazon Lex is an AWS service for building conversational interfaces for applications using phonation and text.Amazon Lex provides the deep functionality and flexibility of natural language understanding (NLU) and automatic spoken language recognition (ASR) so you can build highly engaging user experiences with lifelike, conversational interactions, and create new categories of products.
What is AWS Lambda?
AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that lawmaking.
Steps:
- Create a Lambda Function.
- Create a Bot.
- Build and test the Bot.
- Create a Facebook page and integrate with the messenger.
ane. Create a Lambda Office.
Starting time, create a Lambda office which fulfils a pizza order. You specify this function in your Amazon Lex bot, which you create in the adjacent department.
- Sign in to the AWS Management Console and open the AWS Lambda console at https://console.aws.amazon.com/lambda/
- ChooseCreate role.
- Select Author from scratch.
- Blazon the name PizzaOrderProcessor.
- For theRuntime, cull the latest version of Node.js.
- For theRole, chooseCreate new role from templates.
- Enter a new part name PizzaOrderProcessorRole.
- ChooseCreate function.
- In the Function code department, chooseEdit code inline, then copy the following Node.js office code and paste it in the window.
'use strict'; // Close dialog with the client, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will get in in 20 minutes") role shut(sessionAttributes, fulfillmentState, message) { return { sessionAttributes, dialogAction: { blazon: 'Close', fulfillmentState, message, }, }; } // --------------- Events ----------------------- function dispatch(intentRequest, callback) { console.log(`request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.name}`); const sessionAttributes = intentRequest.sessionAttributes; const slots = intentRequest.currentIntent.slots; const crust = slots.crust; const size = slots.size; const PizzaKind = slots.PizzaKind; callback(close(sessionAttributes, 'Fulfilled', {'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${PizzaKind} pizza on ${crust} crust`})); } // --------------- Chief handler ----------------------- // Route the incoming asking based on intent. // The JSON body of the request is provided in the consequence slot. exports.handler = (event, context, callback) => { effort { acceleration(event, (response) => { callback(nil, response); }); } catch (err) { callback(err); }
};
- ChooseSalve.
- Examination the Lambda Function Using Sample Outcome Data.
- On the function page, in the list of exam events, chooseConfigure examination events.
- ChooseCreate new examination consequence.
- In the Event name field, enter a name for the issue PizzaOrderProcessorTest.
- Copy the following Amazon Lex event into the window.
{ "messageVersion": "1.0", "invocationSource": "FulfillmentCodeHook", "userId": "user-1", "sessionAttributes": {}, "bot": { "name": "PizzaOrderingApp", "alias": "$LATEST", "version": "$LATEST" }, "outputDialogMode": "Text", "currentIntent": { "name": "OrderPizza", "slots": { "size": "large", "pizzaKind": "meat", "crust": "thin" }, "confirmationStatus": "None" }
}
- ChooseCreate.
- CullTest and Lambda runs your Lambda function.
- In the event box, cullDetails. The console displays the following output in the Execution result pane.
ii. Create a Bot.
- Go to services console, type lex and select Amazon Lex.
- select Become Started and then select Create.
- On the Create your Lex bot page, chooseCustom bot.
- App proper noun: PizzaOrderingBot
- Output phonation: Salli
- Session timeout: 5 minutes.
- Child-Directed: Choose the appropriate response.
- Select Create.
At present, create the OrderPizza intent , an action that the user wants to perform, with the minimum data needed. You add together slot types for the intent and then configure the intent later.
- In the Amazon Lex console chooseCreate new intent.
- In the Create intent dialogue box, type the name of the intent OrderPizza, and and then chooseAdd together.
To create slot types
- In the left menu, cull the plus sign (+) next toSlot types.
- Select Slot blazon name – Crusts
- Description – Available crusts
- ChooseRestrict to Slot values and Synonyms
- Value – Type thick. Printing tab and in the Synonym field type stuffed. Choose the plus sign (+). Type thin and and then choose the plus sign (+) over again.
- CullAdd slot to intent.
- On the Intent page, chooseRequired. Change the name of the slot fromslotOnetocrust
- Change the prompt toWhat kind of crust would y'all similar?
- Repeat the previous steps using the values in the following table
After Adding the values it should look like this.
Configure the OrderPizza intent to fulfill a user's request to order a pizza.
Under Select utterances Blazon the following strings. The curly braces {} enclose slot names.
- I want to order pizza, please
- I want to gild a pizza
- I want to order a{pizzaKind} pizza
- I want to order a{size}{pizzaKind} pizza
- I want a{size}{crust} crust{pizzaKind} pizza
- Can I become a pizza, please
- Tin can I get a{pizzaKind} pizza
- Tin I go a{size} {pizzaKind} pizza
- In Lambda initialization and validation Leave the default setting.
- In Confirmation prompt, you tin can Leave the default setting or provide a confirmation string.
- In Fulfillment ChooseAWS Lambda function and select the earlier created PizzaOrderProcessor lambda function.
- Cull ok to the Add permission to Lambda role dialog box
- Leave None selected.
Build and test the bot
- To build the PizzaOrderingBot bot, cullBuild.
- It can take some fourth dimension to complete the build.
- In the Test Bot window, start communicating with your Amazon Lex bot.
- After testing if your bot works fine click the publish button.
- Select Alias BETA.
At present we volition Integrate this Chat bot to our Facebook folio.
- Click Go to channels and select facebook
- Provide a Channel Name and Description
- Go on IAM function as at is.
- Select KMS Key as awslex.
- Select alias equally BETA.
- In Verify token y'all can mention whatsoever proper name just don't misplace it as we are going to need it in our further steps.
- For Access folio token you need to create a Facebook page. I have already created my facebook page.
- Now open up a new tab and type https://developers.facebook.com/ to go Facebook developers page.
- select create new app.
- Provide a proper name of your app and contact email.
- Select the option that suits you lot the all-time for who tin can use the app section.
- Click Create app ID
- Navigate to the messenger choice and click set up
- Select Messenger>Settings.
- Under Pages Select your facebook page and select Generate token.
- Note downward the token.
- For App secret central Select Settings>basic.
- Click show in app secret and note downwardly the app secret primal.
- Now navigate to this earlier aqueduct folio and provide the page access token and app hush-hush key.
- Select Activate.
- Now Re-create the endpoint URL and get the developer (facebook) page.
- Now under messenger>settings>webhooks add the URL in the callback URL space and subscribe for messages.
- At present navigate to your facebook folio and under send message select test button.
- Now blazon to order, your pizza ordering bot should answer.
I promise this article was Informative, and accept added a solid base of operations to your chatbot development process. If you lot have any queries you lot can always contact hither https://www.linkedin.com/in/sourav-sutradhar-b78075149/. I would exist happy to assist yous.
Others besides viewed
Source: https://www.linkedin.com/pulse/creating-chatbot-amazon-lex-aws-lambda-integrate-sourav-sutradhar
Belum ada Komentar untuk "How to Upload a Bot to Aws"
Posting Komentar