[Report] ARC328 – Creating a Support Chatbot #reinvent

2018.12.09

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

I participated in the ARC328 - Creating a Support Chatbot of the builders session.

The builders session is a group session with AWS Solution Architect and five participants.

Builders Sessions

画像

Overview

To quote the event catalog.

In this session, create a conversational interface with Amazon Lex which recognizes and answers common questions received through chat or voice. Become familiar with an Amazon Lex chatbot and its constructs, such as intents, utterances, and slots.

Architecture

AWS services used this time:

  • Amazon Lex
  • AWS Lambda
  • Amazon S3
  • Cognito

Deployment

We will present AWS's solution architect, and will build it according to the following documents:

Module 1: Static Web Hosting with Amazon S3

In this module, we host a static website on Amazon S3. We build this using CloudFormation.

  • Type Website Bucket Name and click Next.

画像

  • Select 'default' on the Options page and click Next.

  • On the Review page, check the box next to I acknowledge that AWS CloudFormation might create IAM resources., and click Create.

画像

  • After stack status becomes CREATE_COMPLETE, we will click WebsiteURL link from Outputs.

画像

  • This completes Module 1.

画像

Module 2: User Registration with Amazon Cognito User Pools

In this module, we create an Amazon Cognito User Pool user to log in.

  • Go to /register.html and create an account.

画像

  • This redirects to /verify.html. Type in the verification code that you receive in your email.

画像 画像

  • Login after redirecting to signin.html.

画像

  • This completes Module 2.

Module 3: Create Chat bot

In this module, we create a chatbot with Amazon Lex.

Step 1: Create the AWS Lambda function

We will create Lambda function using CloudFormation template. Proceed with all settings on default.

Step 2: Configure Cognito pool id in Lambda function

Here, we modify the Lambda function.

  • Copy Cognito User Pool Id from Resource of CloudFormation stack supportchatbot-webapp-1

画像

  • Open the Lambda function(support-chatbot-function) that is created, modify PoolID and then Save.
import json
import boto3

client = boto3.client('cognito-idp')

with open('./response.json', 'r') as r:
    response = json.load(r)
    response_success = response['response_success']
    response_fail = response['response_fail']

#use your cognito user pool ID
PoolID = 'xxxxxxx'

Step 3: Creating your Bot

  • Download json file prepared in advance. VirtualHelpDesk.zip

  • Go to Amazon Lex console. Import the zip file we downloaded earlier.

画像 画像

  • Click Build to create a bot.

画像 画像

  • When Build is completed, try typing I forgot my password on the screen on the right.

画像

Step 4: Integrating the bot with Lambda and test it

  • Go to the Fulfillment session, select the Lambda function we just created and set version to $LATEST. Keep the same settings for both intent, UnlockAccount and PWReset.

画像 画像

  • Click Save Intent to save.

  • Click Build to build the chatbot.

画像

Step 5: Test Password Reset and Account Unlock Intent

  • In the VirtualHelpDesk chatbot, open Test bot and type I forgot my password.

  • We will follow the chatbot's support instructions. At the end, you will see the following response, and the reset code is sent to the email address.

Great, you're all set. Check your email for further instructions.
  • When we receive the email, go to /forgotPassword.html and reset the password.

画像 画像

  • After resetting the password, move to /signin.html and login with the new password.

画像

  • Test with the UnlockAccount intent.

  • From Cognito's management console, change Cognito User Pool(SupportChatbot) → Users and Groups → user to Disable.

画像

  • Open Test bot with UnlockAccount intent and type I think my account is locked.

  • Follow the chatbot's support instructions. At the end, you will see the following response, which unlocks the user.

Great, you're all set. Try logging in now

At this point we can confirm that Account Status is Enabled.

画像

  • Go to /signin.html and check if login is possible.

Step 6: Host the bot with-in a Web Application

Launch the CloudFormation stack.

  • In the Lex Bot Configuration Parameters, type BotName :VirtualHelpDesk
  • In the Web Application Parameters, type each of the parameters.

WebAppConfBotInitialText : Hello, How can I help you? WebAppConfBotInitialSpeech : I forgot my password WebAppConfToolbarTitle : VirtualHelpDesk

  • When Stack status becomes CREATE_COMPLETE, check Outputs and open ParentPageURl, the chatbot will be displayed as iFrame.

画像 画像

Conclusion

I plan to use chatbots more often from now on. please see the details of github's aws-samples/support-chat-bot. I am eagerly waiting for Amazon Lex's Japanese language response, which I will study in detail.

Reference