AWS Lex + Lambda - Intercepting all of next user response regardless of context - without defining sample utterances?

蓝咒 提交于 2021-01-27 12:04:00

问题


Consider the following scenario (U=User, L=Lex):

U1: Hello

L1: Hello, please give me your name to get started.

U2: Bob

L2: Bob, consider the following question: What colour is the sky?

U3: The sky is usually blue but sometimes the sky is red.

The system reads a database of questions and randomly chooses one to present to the user. This is done via AWS Lambda and the question is presented to the user in message L2.

Is there any way to say that 'the next response from the user should be treated as their answer to the question without defining utterances etc? This is because the questions that the bot sends across can vary to a great degree.

I need a way to pass all of block U3 back to Lambda for processing. How would I achieve this regardless of context? (I am using python for Lambda)

Thanks


回答1:


Lex always passes the entire user's input in the Request under the field inputTranscript.

Lex-Lambda Event Format:

inputTranscript – The text used to process the request.

If the input was text, the inputTranscript field contains the text that was input by the user.

If the input was an audio stream, the inputTranscript field contains the text extracted from the audio stream. This is the text that is actually processed to recognize intents and slot values.

This is the format of the Lex Request received by Lambda as event:

{
  "currentIntent": {
    "name": "intent-name",
    "slots": {...},
    "slotDetails": {...},
    "confirmationStatus": "(None, Confirmed, or Denied)"
  },
  "bot": {...},
  "userId": "XXXX",
  "invocationSource": "(FulfillmentCodeHook or DialogCodeHook)",
  "outputDialogMode": "(Text or Voice)",
  "messageVersion": "1.0",
  "sessionAttributes": {...},
  "requestAttributes": {...}
  "inputTranscript": "Text of full user's input utterance",
}

So in Lambda, you can access the inputTranscipt with:

userInput = event.inputTranscript


来源:https://stackoverflow.com/questions/51101099/aws-lex-lambda-intercepting-all-of-next-user-response-regardless-of-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!