检测机器人是否使用语音:RequestAttribute 为空

Detect whether bot is using voice: RequestAttribute is null

根据这个,可以检查lexEventrequestAttributes属性来判断传入请求是否支持语音。

但是,在我的 C# Lambda 中,属性 为空:

public LexResponse FunctionHandler(LexEvent lexEvent, ILambdaContext context)
{
    LambdaLogger.Log($"Request Populated: {lexEvent.RequestAttributes != null}");

已记录:

2020-08-20 18:03:04: START RequestId: f363e694-77e4-40fe-b607-ddaf51b6852f Version: $LATEST
2020-08-20 18:03:04: Request Populated: False

在 C# 开发人员工具包的上下文中,如何确定我的 lambda 正在处理的请求是语音还是文本?

Lambda Input Event包括outputDialogMode:

"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",

AWS文档进一步解释:

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.

因此您的 Lambda 函数应该能够检查 lexEvent.outputDialogMode 是“语音”还是“文本”,然后您可以根据此做出适当的响应。