According to this question, the requestAttributes
property of lexEvent
can be checked to determine whether an incoming request supports voice.
However, in my C# Lambda, that property is null:
public LexResponse FunctionHandler(LexEvent lexEvent, ILambdaContext context)
{
LambdaLogger.Log($"Request Populated: {lexEvent.RequestAttributes != null}");
Logged:
2020-08-20 18:03:04: START RequestId: f363e694-77e4-40fe-b607-ddaf51b6852f Version: $LATEST
2020-08-20 18:03:04: Request Populated: False
How, in the context of the C# developer's kit, can I determine whether the request my lambda is processing is voice or text?
The Lambda Input Event includes outputDialogMode
:
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
The AWS document further explains:
outputDialogMode – For each user input, the client sends the request to Amazon Lex using one of the runtime API operations, PostContent or PostText. Amazon Lex uses the request parameters to determine whether the response to the client is text or voice, and sets this field accordingly.
The Lambda function can use this information to generate an appropriate message. For example, if the client expects a voice response, your Lambda function could return Speech Synthesis Markup Language (SSML) instead of text.
So your Lambda function should be able to check lexEvent.outputDialogMode
as either "Voice" or "Text" and then you can respond appropriately based on that.