【发布时间】:2020-07-16 17:33:15
【问题描述】:
我创建了 Lex 聊天机器人并开发了一个网站并集成了这个聊天机器人。它工作正常。但是按钮形式的响应卡没有显示出来。我知道我必须从 lambda 函数调用它。所以我包含了响应卡代码。它可以工作,但是在显示按钮后它会返回并再次询问第一个槽值。我不知道我错在哪里
这是预期的对话。
用户:嗨
Lex:请提供你的开斋节
用户:e123456
Lex:选择以下影响之一:
1.low 2.high 3.medium(按钮形式)
用户点击率低
Lex:谢谢,你的票已经涨了(预计)
会发生什么:
用户:嗨
Lex:请提供你的开斋节
用户:e123456
Lex:选择以下影响之一:
1.低 2.高 3.中
用户点击率低
Lex:请提供您的 eid(返回并询问第一个 slot 值)
这是我的代码:
import json
import logging
import re
import http.client
import mimetypes
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def elicit_slot_response(output_session_attributes,intent_name,slot_to_elicit,message):
responses= {
'dialogAction': {
'type': 'ElicitSlot',
'slottoElicit':'slot_to_elicit',
'message': {
'contentType': 'PlainText',
'content': message
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'title1',
'subTitle': 'subtitle',
"buttons":[
{
"text":"button 1",
"value":"value 1"
},
{
"text":"button 2",
"value":"value 2"
},
{
"text":"button 3",
"value":"value 3"
}
]
}
]
}
}
}
return responses
def close():
val= {
"dialogAction":
{
"fulfillmentState":"Fulfilled",
"type":"Close",
"message":
{
"contentType":"PlainText",
"content":"Hey your ticket has been raised"
}
}
}
print(val)
return val
def lambda_handler(event, context):
val = ""
slots = event['currentIntent']['slots']
empidemployee= event['currentIntent']["slots"]["empidemployee"]
latestdesc= event['currentIntent']["slots"]["latestdesc"]
latestimpact= event['currentIntent']["slots"]["latestimpact"]
output_session_attributes = event['sessionAttributes'] if event['sessionAttributes'] is not None else {}
elicit_slot_response(output_session_attributes,'latestdetails','latestimpact',"impact")
val=close()
return val
【问题讨论】:
标签: aws-lambda amazon-lex