在 AWS LEX 中从一个意图调用另一个意图
Calling from one intent to another intent in AWS LEX
我是 AWS 领域的新手。现在我正在研究 AWS LEX。我想从一个意图调用另一个意图。我发现了以下问题,但由于我无法发表评论,所以我创建了另一个问题。
我的问题是我将把上述第一种方法的代码放在哪里link?
如何从 Intent 中调用 lambda 函数以及 JavaScript 中的代码格式是什么?
My question is where will i put the codes of the 1st method from the
above link?
当调用 intent-A 并且您正在响应用户时,您将使用该代码。基本上我们使用 ConfirmIntent
.
而不是 dialogAction
类型 Close
您可以阅读有关响应格式 here.
的更多信息
完整代码:
def build_response(message):
return {
"dialogAction":{
"type":"Close",
"fulfillmentState":"Fulfilled",
"message":{
"contentType":"PlainText",
"content":message
}
}
}
def delegate(session_attributes, slots):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Delegate',
'slots': slots
}
}
def confirm_intent(session_attributes, intent_name, slots, message):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'ConfirmIntent',
'intentName': intent_name,
'slots': slots,
'message': {
'contentType': 'PlainText',
'content': message
}
}
}
def perform_action_A(intent_request):
source = intent_request['invocationSource']
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
slots = intent_request['currentIntent']['slots']
# whatever you want to do
if source == 'DialogCodeHook':
# Perform basic validation on the supplied input slots.
return delegate(output_session_attributes, slots)
if source == 'FulfillmentCodeHook':
# action fulfillment code
msg = "Hi, I am a xxx-BOT. i can help you with following: A B C"
return confirm_intent(output_session_attributes, 'intent-B', slots, msg)
def perform_action_B(intent_request):
# some code
if source == 'DialogCodeHook':
# Perform basic validation on the supplied input slots.
return delegate(output_session_attributes, slots)
if source == 'FulfillmentCodeHook':
# action fulfillment code
build_response('Final close message')
def dispatch(intent_request):
intent_name = intent_request['currentIntent']['name']
# Dispatch to your bot's intent handlers
if intent_name == 'intent-A':
return perform_action_A(intent_request)
if intent_name == 'intent-B':
return perform_action_B(intent_request)
raise Exception('Intent with name ' + intent_name + ' not supported')
def lambda_handler(event, context):
logger.debug(event)
return dispatch(event)
How to call a lambda function from a intent and what is the code
format in javascript?
我没有在 javascript 中编写任何 lex bot,也许 this link 可以帮助你。
测试事件代码:
{
"currentIntent": {
"name": "intent-A",
"slots": {
}
},
"invocationSource": "DialogCodeHook",
"sessionAttributes": {},
"bot": {
"name": "Your_Bot_Name"
},
"userId": "Some_User_Id"
}
对于 Fulfillment,将 invocationSource
的值更改为 FulfillmentCodeHook
。还有,有槽就给个槽
澄清一下,configure test events
用于通过模拟请求来测试 Lambda 代码。您可以直接将 Lambda 函数与 Lex 集成并使用 Lex 控制台进行测试。
希望对您有所帮助。
编辑 1: 用代码更新了答案。
编辑 2: 更新了测试事件代码。
我是 AWS 领域的新手。现在我正在研究 AWS LEX。我想从一个意图调用另一个意图。我发现了以下问题,但由于我无法发表评论,所以我创建了另一个问题。
我的问题是我将把上述第一种方法的代码放在哪里link?
如何从 Intent 中调用 lambda 函数以及 JavaScript 中的代码格式是什么?
My question is where will i put the codes of the 1st method from the above link?
当调用 intent-A 并且您正在响应用户时,您将使用该代码。基本上我们使用 ConfirmIntent
.
而不是 dialogAction
类型 Close
您可以阅读有关响应格式 here.
完整代码:
def build_response(message):
return {
"dialogAction":{
"type":"Close",
"fulfillmentState":"Fulfilled",
"message":{
"contentType":"PlainText",
"content":message
}
}
}
def delegate(session_attributes, slots):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Delegate',
'slots': slots
}
}
def confirm_intent(session_attributes, intent_name, slots, message):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'ConfirmIntent',
'intentName': intent_name,
'slots': slots,
'message': {
'contentType': 'PlainText',
'content': message
}
}
}
def perform_action_A(intent_request):
source = intent_request['invocationSource']
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
slots = intent_request['currentIntent']['slots']
# whatever you want to do
if source == 'DialogCodeHook':
# Perform basic validation on the supplied input slots.
return delegate(output_session_attributes, slots)
if source == 'FulfillmentCodeHook':
# action fulfillment code
msg = "Hi, I am a xxx-BOT. i can help you with following: A B C"
return confirm_intent(output_session_attributes, 'intent-B', slots, msg)
def perform_action_B(intent_request):
# some code
if source == 'DialogCodeHook':
# Perform basic validation on the supplied input slots.
return delegate(output_session_attributes, slots)
if source == 'FulfillmentCodeHook':
# action fulfillment code
build_response('Final close message')
def dispatch(intent_request):
intent_name = intent_request['currentIntent']['name']
# Dispatch to your bot's intent handlers
if intent_name == 'intent-A':
return perform_action_A(intent_request)
if intent_name == 'intent-B':
return perform_action_B(intent_request)
raise Exception('Intent with name ' + intent_name + ' not supported')
def lambda_handler(event, context):
logger.debug(event)
return dispatch(event)
How to call a lambda function from a intent and what is the code format in javascript?
我没有在 javascript 中编写任何 lex bot,也许 this link 可以帮助你。
测试事件代码:
{
"currentIntent": {
"name": "intent-A",
"slots": {
}
},
"invocationSource": "DialogCodeHook",
"sessionAttributes": {},
"bot": {
"name": "Your_Bot_Name"
},
"userId": "Some_User_Id"
}
对于 Fulfillment,将 invocationSource
的值更改为 FulfillmentCodeHook
。还有,有槽就给个槽
澄清一下,configure test events
用于通过模拟请求来测试 Lambda 代码。您可以直接将 Lambda 函数与 Lex 集成并使用 Lex 控制台进行测试。
希望对您有所帮助。
编辑 1: 用代码更新了答案。
编辑 2: 更新了测试事件代码。