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

发送交互式消息/模板后未收到WhatsApp Flows的INIT动作求助

问题:如何触发WhatsApp Flows的INIT动作?

需求:用户点击消息中的“Fill form”按钮打开表单时,自动触发INIT动作。

已尝试操作:

  • 使用多种营销类、实用类模板发送初始消息
  • 在模板消息的payload中加入"INIT"动作参数
  • 尝试interactive类型消息

遇到的问题:

  • 始终未收到INIT动作请求,日志中仅持续出现ping动作
  • 只有提交MYFIRSTSCREEN的data_exchange时才有后续日志,但user_id需要从INIT动作获取,导致流程无法推进

测试例外情况:

  • 使用Flow Builder测试时,INIT动作能正常发送(响应码200),且可在日志中看到记录

补充需求:
若无法定位触发INIT的错误,也请告知如何在流程中获取user_id(解密后的请求体仅包含提交的data_exchange数据)


相关代码示例

1. Interactive类型消息代码

message = {
        "messaging_product": "whatsapp",
        "recipient_type": "individual",
        "to": user_id,
        "type": "interactive",
        "interactive": {
            "type": "flow",
            "header": {
                "type": "text",
                "text": "Welcome"
            },
            "body": {
                "text": "Click fill form"
            },
            "action": {
                "name": "flow",
                "parameters": {
                    "flow_message_version": "3",
                    "flow_cta": "Fill form",
                    "flow_name": "my_main_form_name"
                }
            }
        }
    }

2. 模板消息代码

message = {
        "messaging_product": "whatsapp",
        "to": user_id,
        "type": "template",
        "template": {
            "name": "main_flow_en",
            "language": {"code": "en"},
            "components": [
                {
                    "type": "body",
                    "parameters": [
                        {
                            "type": "text",
                            "parameter_name": "profile_name",
                            "text": profile_name
                        }
                    ]
                },
                {
                    "type": "button",
                    "sub_type": "flow",
                    "index": "0",
                    "parameters": [
                        {
                            "type": "payload",
                            "payload": json.dumps({
                                "action": "INIT",
                                "data": {
                                    "to_number": str(user_id)
                                }
                            })
                        }
                    ]
                }
            ]
        }
    }

3. 其他按钮参数尝试

{
                    "type": "button",
                    "sub_type": "flow",
                    "index": "0",
                    "parameters": [
                        {
                            "type": "action",
                            "action": {
                                "flow_action_data": {
                                    "user_id": user_id,
                                    "user_name": profile_name
                                }
                            }
                        }
                    ]
                }

4. Flow端点处理代码

def handle_form_submission(event, context):
    body = json.loads(event.get('body', '{}'))
    decrypted  = decrypt_flow_data(body)
    logger.info("✅ Decrypted body: %s", decrypted)

    user_id = decrypted.get('to_number')
    action = decrypted.get('action')
    screen = decrypted.get('screen')
    data = decrypted.get('data') or {}
    flow_token = decrypted.get('flow_token')

    if action == 'INIT':
        logger.info("🚀 INIT state")
        profile = get_user_profile(user_id)
        store_user_data(user_id, {
            'SK': 'META',
            'flow_token': flow_token,
            'profile_name': profile,
            'started_at': iso_now()
        })
        response = {'version': '3.0', 'screen': 'MYFIRSTSCREEN',
                    'data': {'greeting': 'Welcome'}}
    elif action == "ping":
        response = {"version": "3.0", "data": {"status": "active"}}
    elif action == 'data_exchange' and screen == 'MYFIRSTSCREEN':
        ....

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 08:49:53