我们的组织想要开发一个“失物招领处系统应用程序”使用聊天机器人集成在一个网站。
每当用户开始与聊天机器人对话时,聊天机器人应该询问丢失的项目或项目的详细信息,并将其存储在数据库中。
我们怎么做呢?
我们是否可以使用我们自己的网络服务,因为组织不想将数据库保存在Amazon的服务器中。
发布于 2018-01-19 07:29:29
作为刚刚实现这种情况的人(在@Sid8491的大量帮助下),我可以给出一些关于我是如何管理它的见解。
注意,我使用的是C#,因为这是我为之工作的公司。
首先,bot需要用户的输入来决定调用什么目的。为此,我实现了对Lex的PostText调用。
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);
}请注意,这要求您已经创建了一个认知对象来验证您的AmazonLexClient (如下所示):
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);
}在我们从bot获得响应后,我们使用一个简单的开关情况来正确识别我们需要调用的方法来运行我们的web应用程序。整个过程由我们的web应用程序处理,我们只使用Lex来标识用户的请求和插槽值。
//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;
}在此之后,只需向用户显示结果。如果你需要更多的澄清,请告诉我!
更新:
要写入SQL的插槽数据的示例实现(同样是在C#中)如下所示:
case "LostItem":
message = "Please fill the following form with the details of the item you lost.";
LostItem();
break;这将带您到LostItem()方法,您可以使用该方法来填充表单。
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是您最好的朋友。希望这能帮上忙!
发布于 2018-01-19 05:20:38
是的,有可能。
您可以从您的网站向Lex发送请求,这将提取意图和实体。
一旦得到这些信息,就可以用您选择的任何语言编写后端代码,并使用您想要的任何DB。
在您的用例中,您可能只想使用Lex。PostText将是您将要调用的主要函数。
您需要在Lex中创建一个意图,它将有多个插槽LosingDate、LosingPlace或您想要的任何东西,然后它将能够从用户那里获得所有这些信息并将其传递给您的web应用程序。
https://stackoverflow.com/questions/48314916
复制相似问题