如何在 REST CLIENT 上测试我发布的 LEX 机器人

15

我已创建了我的Lex机器人并发布了它。现在我正在尝试从rest客户端测试它。

这个想法是一旦从rest客户端工作正常,我就可以使用rest调用将其与我的自定义UI集成。

输入图像描述

我正在使用此请求正文(posttext)作为此链接中的内容: http://docs.aws.amazon.com/lex/latest/dg/API_runtime_PostText.html

当我从rest客户端使用它时,我收到“缺少身份验证令牌”的错误信息。

输入图像描述

使用的终端点URL是https://runtime.lex.us-east-1.amazonaws.com

我应该在授权标头中添加AWS签名或其他内容来使其正常工作吗?


1
你有查看过Amazon Lex的身份验证和访问控制吗? - Michael - sqlbot
1个回答

12

您需要在Authorization选项卡中包含AWS签名,其中包含具有运行Lex机器人访问权限的IAM用户的详细信息。

步骤: 1. 在AWS中进入IAM -> 用户 -> 添加用户

enter image description here

  1. 给它一个用户名,例如“myBotUser”,并选择“编程访问”作为访问类型。点击下一步:权限。

enter image description here

  1. 点击“创建组”以创建一个组,并授予权限给该用户。

enter image description here

  1. 给它一个名称,然后过滤Lex策略,选择“AmazonLexReadOnly”和“AmazonLexRunBotsOnly”。

enter image description here

点击“创建组”。

  1. 然后点击“下一步:审核”。
  2. 之后点击“Create User”- 您的IAM用户已准备就绪。您将看到访问密钥ID和秘密访问密钥。

  3. 在Postman中,在Authorization中选择AWS签名,并输入Access key ID和Secret Access Key,以及"us-east-1"作为AWS区域和"lex"作为服务名称:

enter image description here

  1. 确保您的请求主体是所需格式(这里我只发送文本):

enter image description here

点击“发送”,您应该会收到类似以下响应:

{
    "dialogState": "Fulfilled",
    "intentName": "yourIntentName",
    "message": "A response for that intent",
    "responseCard": null,
    "sessionAttributes": {},
    "slotToElicit": null,
    "slots": {}
}

更新

还要注意 - POST url 的格式应该为:

https://runtime.lex.us-east-1.amazonaws.com/bot/MyBotName/alias/myMyAlias/user/aUniqueUserID/text and it should be a POST

还要确保头文件 Content-Type 是 application/json,正如正文一样。


我做了所有的事情,但是出现了这个错误:“发送请求时出错:在XMLHttpRequest上执行'setRequestHeader'失败:'runtime.lex.us-east-1.amazonaws.com'不是有效的HTTP头字段值”。这是因为端点URL不正确吗?如果是,那么调用已发布的Lex机器人的正确URL应该是什么,包括机器人名称和别名名称。 - lost Coder
{ "inputText": "我想发起一个工单", "sessionAttributes": { "string" : "string" } } - lost Coder
请求好像没有发送成功。 - lost Coder
POST /bot/test/alias/lexTestChat/user/unique123r/text HTTP/1.1 Content-Type: application/json Host: runtime.lex.us-east-1.amazonaws.com​ X-Amz-Date: 20170712T123140Z Authorization: AWS4-HMAC-SHA256 Credential=xxxxxxxxxx/20170712/us-east-1/lex/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Cache-Control: no-cache Postman-Token: 46f48b78-ab05-1f1b-5f37-bceb4e02dc9e{ "inputText": "我想提一个工单", "sessionAttributes": { "string" : "string" } } - lost Coder
请查看聊天记录,我已经发布了适用于Postman的JSON代码,应该可以正常工作。 - AndyOS
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接