我用简单的lex意图创建了一个简单的bot。这个lex意图有一个单一的插槽slotTwo
。
然后我将它与python lambda函数链接。我想从lambda函数内部访问该槽的值。
python lambda函数接收参数context
和event
。下面的链接显示了参数event
的结构。 https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html
I copy it here too:
{
"currentIntent": {
"name": "intent-name",
"slots": {
"slot name": "value",
"slot name": "value"
},
"slotDetails": {
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
},
"slot name": {
"resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" }
],
"originalValue": "original text"
}
},
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
},
"bot": {
"name": "bot name",
"alias": "bot alias",
"version": "bot version"
},
"userId": "User ID specified in the POST request to Amazon Lex.",
"inputTranscript": "Text used to process the request",
"invocationSource": "FulfillmentCodeHook or DialogCodeHook",
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"messageVersion": "1.0",
"sessionAttributes": {
"key": "value",
"key": "value"
},
"requestAttributes": {
"key": "value",
"key": "value"
}
}
但是,当我打印出这个参数的内容时,我只看到了插槽,我可以直接访问它的值,第一级。
START RequestId: 60a541d8-b3c8-48b0-a7a3-6b3f65d96482 Version: $LATEST
{
"slotTwo": "some text here"
}
lambda控制台的测试工作正常。它能够检索值并继续逻辑。但是,当我从Lex测试机器人时,它不起作用。知道为什么吗?非常感谢Ester
我的错。我错过了lamdda测试中指示的值必须对应于整个JSON结构。所以现在我把它添加为事件测试:
{
"currentIntent": {
"name": "intent-name",
"slots": {
"slotTwo": "Hi from the sendmessagetest"
}
}
}
我以这种方式访问lambda中的插槽:
messagetext = event['currentIntent'] ['slots'] ['slotTwo']
如果您发现它令人困惑,请随意删除我的帖子。感谢大家