You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS LexV2集成Facebook Messenger通道requestAttributes缺失问题

AWS LexV2对接Facebook Messenger Lambda事件缺失requestAttributes字段解决建议

问题说明

我正在搭建AWS LexV2聊天机器人,计划通过LexV2提供的通道集成能力对接Facebook Messenger,同时使用Lambda codehook完成输入校验和意图实现。按照官方文档操作后所有功能都正常,仅存在一个问题:我在Lambda函数中打印event对象时,发现该对象缺少requestAttributes字段。

相关代码与日志

Lambda函数代码

import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

def lambda_handler(event, context):
    logger.error(event)
    return ...

LexV2实际返回Lambda的事件内容

当向Facebook上的对应应用/主页发送消息时,日志打印内容如下:

{
    "sessionId": "session-id",
    "inputTranscript": "Intent utterance",
    "interpretations":
    [
        {
            "intent":
            {
                "slots":
                {
                    "slot1": null,
                    "slot2": null
                },
                "confirmationState": "null",
                "name": "IntentName",
                "state": "InProgress"
            },
            "nluConfidence": 1.0
        },
        {
            "intent":
            {
                "slots":
                {},
                "confirmationState": "null",
                "name": "FallbackIntent",
                "state": "InProgress"
            }
        }
    ],
    "responseContentType": "text/plain; charset=utf-8",
    "invocationSource": "DialogCodeHook",
    "messageVersion": "1.0",
    "sessionState":
    {
        "intent":
        {
            "slots":
            {
                "slot1": null,
                "slot2": null
            },
            "confirmationState": "null",
            "name": "IntentName",
            "state": "InProgress"
        },
        "originatingRequestId": "req-id"
    },
    "bot":
    {
        "aliasId": "ALIASID",
        "aliasName": "AliasName",
        "name": "BotName",
        "version": "DRAFT",
        "localeId": "en_US",
        "id": "bot-id"
    },
    "inputMode": "Text"
}

注:为方便JSON格式化,已将Python的None替换为null;日志中的ID和名称已替换为通用占位符

LexV1对接同个Facebook通道的正常返回参考

使用同一个Facebook主页/Messenger应用对接LexV1机器人时,可以正常获取到该字段,示例如下:

{
    "requestAttributes":
    {
        "x-amz-lex:facebook-page-id": "page-id",
        "x-amz-lex:channel-id": "channel-id",
        "x-amz-lex:webhook-endpoint-url": "webhook-endpoint",
        "x-amz-lex:accept-content-types": "PlainText",
        "x-amz-lex:user-id": "user-id",
        "x-amz-lex:channel-name": "channel-name",
        "x-amz-lex:channel-type": "Facebook"
    }
}

可行解决建议

  • 首先检查LexV2关联Lambda的别名配置:LexV2默认不会自动传递通道元数据到Lambda事件,需要在机器人别名的「Lambda代码钩子」设置中开启请求属性传递选项,保存后重新测试。
  • 检查Facebook通道的集成配置:进入LexV2控制台对应机器人的「通道集成」-「Facebook」页面,确认已勾选「传递通道元数据到Lambda函数」的可选配置,重新部署机器人别名后验证。
  • 检查Session属性传递配置:如果上述配置都已开启,可尝试在Lambda返回的响应中主动在sessionAttributes字段添加占位,触发LexV2在后续请求中携带完整的属性字段。
  • 确认机器人版本:如果使用的是DRAFT版本测试,可先发布一个正式版本,将通道关联到正式别名再测试,部分DRAFT版本的通道集成存在属性不传递的已知问题。

内容的提问来源于stack exchange,提问作者Bulse Eye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 06:54:00