[Python] How to auto-select the "Good" option in ChipsSelector in WhatsApp Flow JSON using...

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'm building a WhatsApp conversational flow using a JSON Flow definition and a Python backend workflow. I have a ChipsSelector in my Flow.json representing feedback options:

    {
    "type": "ChipsSelector",
    "name": "chips",
    "label": "How Was Your Experience?",
    "max-selected-items": 1,
    "data-source": [
    { "id": "1", "title": " Needs Improvement" },
    { "id": "2", "title": " Not Great" },
    { "id": "3", "title": " Okay" },
    { "id": "4", "title": " Good" },
    { "id": "5", "title": " Loved It!" }
    ]
    }


    I want to autofill or auto-select the " Good" option (which has "id": "4") when the user lands on the feedback screen.

    if action == "INIT":
    screen_name = "FEEDBACK" if extra_token == "FEEDBACK" else "FEEDBACK"
    userSession["currentScreen"] = screen_name
    userSession["selections"] = {}
    userSession["cart"] = []

    response = {"screen": screen_name, "data": {}}
    print("Before:", response)

    if screen_name == "FEEDBACK":
    # Must match the chips component ID in your flow JSON
    response["data"]["chips"] = ["4"] # 4 is the Good option's ID in Flow JSON
    print("DEBUG FEEDBACK RESPONSE:", response)

    return encryptResponse(
    response,
    decryptedData["aesKeyBuffer"],
    decryptedData["initialVectorBuffer"],
    )


    This is my Feedback.py

    def handle(userSession, formData):
    userSession["feedback"] = {
    "selected": formData.get("chips"),
    "text_area": formData.get("textarea", "")
    }
    return {
    "data": {
    "selected": formData.get("chips"),
    "text_area": formData.get("textarea", "")
    }
    }



    This is my flow.json

    {
    "version": "6.3",
    "data_api_version": "3.0",
    "routing_model": {
    "FEEDBACK": []
    },
    "screens": [
    {
    "id": "FEEDBACK",
    "terminal": true,
    "title": "Help Us Serve You Better",
    "data": {},
    "layout": {
    "type": "SingleColumnLayout",
    "children": [
    {
    "type": "Form",
    "name": "text_input_form",
    "children": [

    {
    "type": "ChipsSelector",
    "required": true,
    "name": "chips",
    "label": "How Was Your Experience?",
    "max-selected-items": 1,
    "data-source": [
    { "id": "1", "title": " Needs Improvement" },
    { "id": "2", "title": " Not Great" },
    { "id": "3", "title": " Okay" },
    { "id": "4", "title": " Good" },
    { "id": "5", "title": " Loved It!" }
    ]
    },

    {
    "type": "TextArea",
    "required": true,
    "label": "How Can We Improve?",
    "name": "textarea"
    },
    {
    "type": "Footer",
    "label": "Submit",
    "on-click-action": {
    "name": "complete",
    "payload": {
    "selected": "${Form.chips}",
    "text_area": "${Form.textarea}"
    }
    }
    }
    ]
    }
    ]
    }
    }
    ]
    }



    I suspect the selection should be done by sending only the IDs, but I’m not sure about the exact response format.

    What is the correct format in the backend response JSON to auto-select a chip in ChipsSelector?

    Should I send just the selected chip IDs (like ["4"]) or full chip objects?

    Are there any other keys or conventions needed for the Flow JSON engine to recognize pre-selected chips?

    Any help or example responses to correctly autofill the "Good" option would be greatly appreciated!

    Thank you!

    What did you try and what were you expecting? I tried this approach in my backend response to auto-select the "Good" chip in the ChipsSelector:

    Sending only the selected chip ID as a list of strings:

    response["data"]["chips"] = ["4"]

    Continue reading...

Compartilhe esta Página