[Python] Not receiving INIT action from WhatsApp Flows after sending an interactive flow or...

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I experimented with sending initial messages using various marketing and utility templates, each with different structures. I employed the same approach I found here, where the action "INIT" is passed in the payload, along with an interactive type. However, I am not receiving the INIT action.

    In the logs, I consistently see a 'ping' action, and then a subsequent log entry appears when I submit my data exchange for MYFIRSTSCREEN. Since the user ID can only be retrieved from the INIT action, I am unable to proceed.

    When testing the flow with the builder, I notice that the INIT action is sent with a response code of 200, and I can see it in the logs in that case.

    Please let me know what I might be doing wrong or how I can obtain a user_id (to_number) while working with the flow. The decrypted body contains only the data that I submitted during the data exchange using the Flow JSON.

    I anticipate that the INIT action will be triggered automatically when the user taps the 'Fill form' button to open the form from my message.

    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"
    }
    }
    }
    }


    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)
    }
    })
    }
    ]
    }
    ]
    }
    }


    And tried these parameters:

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


    Flow endpoint code:

    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':
    ....

    Continue reading...

Compartilhe esta Página