是否可以使用AMAZON LEX构建一个聊天机器人,该机器人与存储在客户端的数据库和Web服务连接? [英] Is it possible to use AMAZON LEX to build a chatbot which connects with database and Web service stored on client side?

查看:74
本文介绍了是否可以使用AMAZON LEX构建一个聊天机器人,该机器人与存储在客户端的数据库和Web服务连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的组织希望使用集成在网站中的聊天机器人来开发失物招领系统应用程序" .

Our organization wants to develop a "LOST & FOUND System Application" using chatbot integrated in a website.

无论何时用户与聊天机器人开始对话,聊天机器人都应询问丢失的物品或找到的物品的详细信息,并将其存储在数据库中.

Whenever the user starts the conversation with the chatbot, the chatbot should ask the details of lost item or item found and it should store the details in database.

我们该怎么做?

并且我们可以使用我们自己的Web服务,因为组织不想将数据库保留在Amazon的Server中.

And can we use our own web-service because organization doesn't want to keep the database in Amazon's Server.

推荐答案

作为刚刚实施过这种情况的人(在@ Sid8491的大量帮助下),我可以提供一些有关如何进行管理的见识.

As someone who just implemented this very same situation (with a lot of help from @Sid8491), I can give some insight on how I managed it.

注意,我正在使用C#,因为这就是我工作的公司.

Note, I'm using C# because that's what the company I work for uses.

首先,机器人需要用户输入才能确定要调用的意图.为此,我实现了对Lex API的PostText调用.

First, the bot requires input from the user to decide what intent is being called. For this, I implemented a PostText call to the Lex API.

PostTextRequest lexTextRequest = new PostTextRequest()
        {
            BotName = botName,
            BotAlias = botAlias,
            UserId = sessionId,
            InputText = messageToSend
        };

        try
        {
            lexTextResponse = await awsLexClient.PostTextAsync(lexTextRequest);
        }
        catch (Exception ex)
        {
            throw new BadRequestException(ex);
        }

请注意,这需要您创建一个Cognito对象来对您的AmazonLexClient进行身份验证(如下所示):

Please note that this requires you to have created a Cognito Object to authenticate your AmazonLexClient (as shown below):

protected void InitLexService()
    {
        //Grab region for Lex Bot services
        Amazon.RegionEndpoint svcRegionEndpoint = Amazon.RegionEndpoint.USEast1;

        //Get credentials from Cognito
        awsCredentials = new CognitoAWSCredentials(
                            poolId,                     // Identity pool ID
                            svcRegionEndpoint);         // Region

        //Instantiate Lex Client with Region
        awsLexClient = new AmazonLexClient(awsCredentials, svcRegionEndpoint);
    }

从机器人获得响应后,我们使用一个简单的开关盒来正确识别我们需要调用的方法以使Web应用程序运行.整个过程由我们的Web应用程序处理,我们仅使用Lex来识别用户的请求和广告位值.

After we get the response from the bot, we use a simple switch case to correctly identify the method we need to call for our web application to run. The entire process is handled by our web application, and we use Lex only to identify the user's request and slot values.

//Call Amazon Lex with Text, capture response
var lexResponse = await awsLexSvc.SendTextMsgToLex(userMessage, sessionID);

//Extract intent and slot values from LexResponse
string intent = lexResponse.IntentName;
var slots = lexResponse.Slots;

//Use LexResponse's Intent to call the appropriate method 
switch (intent)
{
    case: /*Your intent name*/:
    /*Call appropriate method*/;
    break;
}

之后,只需要向用户显示结果即可.如果需要进一步说明,请告诉我!

After that, it is just a matter of displaying the result to the user. Do let me know if you need more clarification!

更新:

用于写入SQL的插槽数据的示例实现(同样在C#中)如下所示:

An example implementation of the slots data to write to SQL (again in C#) would look like this:

 case "LostItem":                                              
      message = "Please fill the following form with the details of the item you lost.";
      LostItem();
      break;

这将带您进入LostItem()方法,您可以使用该方法来填写表格.

This would then take you to the LostItem() method which you can use to fill up a form.

public void LostItem()
{
    string itemName = string.Empty;
    itemName = //Get from user
    //repeat with whatever else you need for a complete item object

    //Implement a SQL call to a stored procedure that inserts the object into your database. 
    //You can do a similar call to the database to retrieve an object as well
}

那应该可以为您指明正确的方向.如果您需要有关SQL存储过程的帮助,则Google是您最好的朋友.希望这会有所帮助!

That should point you in the right direction hopefully. Google is your best friend if you need help with SQL stored procedures. Hopefully this helped!

这篇关于是否可以使用AMAZON LEX构建一个聊天机器人,该机器人与存储在客户端的数据库和Web服务连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆