如何在AWS lex中从意图A调用意图B? [英] How to call Intent B from intent A in AWS lex?
问题描述
我正在研究AWS lex
我有一个意图-A.我将其命名为welcomeMsg
.我想从intent-A
呼叫另一个intent(B)
.在欢迎msg(intent-A)
中,它将说:
I am working on aws lex
I have an intent-A. I named it welcomeMsg
. I want to call another intent(B)
from intent-A
. In welcome msg(intent-A)
, it will say:
> `"Hi, I am a xxx-BOT. i can help you with following:`
A
B
C
如果我说B,它应该转到intent-B.这是我想要做的,但我无法实现.对python代码的任何帮助将不胜感激.
If I Say B, it should go to intent-B . This is what I want to do but I am unable to achieve this. Any help in python code will be appreciated .
推荐答案
我发现了这三种从intent-A调用intent-B的方法.
I have found these 3 methods for calling intent-B from intent-A.
第一种方法(使用ConfirmIntent):
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
}
}
}
msg = "Hi, I am a xxx-BOT. i can help you with following: A B C"
return confirm_intent(output_session_attributes, 'intent-B', new_slot, msg)
第二种方法(假装为Lex并调用Lambda方法):
client = boto3.client('lambda')
data = {'messageVersion': '1.0', 'invocationSource': 'FulfillmentCodeHook', 'userId': '###',
'sessionAttributes': {}, 'requestAttributes': None,
'bot': {'name': '###', 'alias': '$LATEST', 'version': '$LATEST'},
'outputDialogMode': 'Text',
'currentIntent': {'name': '###', 'slots': {'###': '###'},
'slotDetails': {'###': {'resolutions': [], 'originalValue': '###'}},
'confirmationStatus': 'None'},
'inputTranscript': '###'}
response = client.invoke(
FunctionName='{intent-B_lambda_function}',
InvocationType='RequestResponse',
Payload=json.dumps(data)
)
output = json.loads(response['Payload'].read())['dialogAction']['message']['content']
第三种方法(使用ElicitSlot):
def elicitSlot(sessionAttributes, intentName, slots, slotToElicit, message):
return {
sessionAttributes,
dialogAction: {
type: 'ElicitSlot',
intentName,
slots,
slotToElicit,
message,
}
}
intentRequest['currentIntent']['name'] = 'intent-B'
param1 = {
slot-B:null
}
intentRequest['currentIntent']['slots'] = param1
return elicitSlot(outputSessionAttributes, 'intent-B', intentRequest['currentIntent']['slots'], 'slot-B', 'some_message')
请检查这些方法,并根据需要进行调整.我认为方法1 将最适合您的需求,并且最简单.
Do check these methods, play with them and tweak according to your need. I think method 1 will best suit your need and it's easiest.
如果遇到一些问题请发表评论.
Comment in case you run into some problems.
希望有帮助.
这篇关于如何在AWS lex中从意图A调用意图B?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!