Accessing more information from WhatsApp reply mes...
# 🤝help
e
My bot sends a template message via the Meta API with custom buttons (shown in the image). Their payload contains an id to allow me retrieving the selected options. The labels I set in the Whatsapp Manager are "Update alert" and "Cancel alert". The problem is that when the user clicks one of these buttons I receive the label only. Is there a way to get the payload as well? This is not a regular choice or card action sent with a Message card which allow getting the payload just fine, in this case it's a custom template message . These are the handler logs for a button click:
Copy code
js
"contacts": [...],
"messages": [
    {
        "context": {
            "from": "bot_phone",
            "id": "wamid=="
        },
        "from": "user_phone",
        "id": "wamid",
        "timestamp": "1710204778",
        "type": "button",
        "button": {
            "payload": "Update alert",
            "text": "Update alert"
        }
    }
]
And the subsequential logs:
Received button message from Whatsapp: { payload: 'Update alert', text: 'Update alert' }
This is how I send the template buttons 👇
The WhatsApp integration should have access to the button's internal payload and text but they're received as the same, so is WhatsApp sending it as the same or could it be the integration settings (specifically these parts https://github.com/botpress/botpress/blob/master/integrations/whatsapp/src/incoming-message.ts#L111 and https://github.com/botpress/botpress/blob/master/integrations/whatsapp/src/whatsapp-types.ts#L76) ? If it's not possible to get the internal payload of a interactive message quick reply, could the context info be appended to the tags in order to make the template message id retrievable? These are the current tags:
Copy code
js
    {
        "message": {
            "whatsapp:id": "wamid"
        },
        "conversation": {
            "whatsapp:userPhone": "user_phone",
            "whatsapp:phoneNumberId": "phone_id"
        },
        "user": {
            "whatsapp:userId": "user_id",
            "whatsapp:name": "Guilhermy"
        }
    }
Having a
message["whatsapp:contextId"]
tag would be a nice solution (for this use case and others) because I would be able to find the exact message that the user clicked (replied) and get the related info! Just like we have in the slack integration with
slack:threadId
Appreciate any suggestions!
l
If the alertID is the same for both update and cancel, search for biz_opaque_callback_data as a parameter that can be added to your API call. I don't know if it solves your purpose, read meta documentation on this topic
e
Hello @limited-pencil-78283, appreciate the suggestion! I just tried it getting the
biz_opaque_callback_data
from event.payload but that property is not made available by Botpress. That would be a solution indeed .
Found part of the issue: I was sending the buttons with the indexes starting at 1, they should start at 0. But still, their internal payload is not passed through to the event.payload
Received button message from Whatsapp: { payload: 'cancel_alert_13', text: 'Cancel alert' }
Printing
event.payload
right after that returns
{"text":"Cancel alert"}
That means the payload is not being forwarded, which is the case for buttons in Captures and Cards .
Could please take a look at this @famous-zoo-73118 ? thank you
f
Yes, there isn't a native "button" message type in BP at the moment, so the WA integration maps it to text (which doesn't support other attributes) by just passing the button label which can be used for conditional logic.
e
But why does it work for capture choices and card actions with postback?
f
I looked at the code, and the way it's implemented is that they're also sent as text messages, but for choice/carousels the choice ID is sent as the text where as for normal buttons it's the button label
e
I see! Thanks for the explanation
Is it something that can be improved in the integration?
And do you suggest any workarounds?
f
Is there something that prevents you from using the button label for detecting which button was pressed? Unfortunately at this point it's not possible to make changes to the current behavior as it would break existing bots, and it requires some thought on how to best implement support for receiving button IDs in a standard and reliable way for both normal buttons and cards, so if you really need to detect button IDs I'd post a feature request for this to see if it gets enough upvotes.
e
I can tell the button that was pressed, the thing is that I need the id of the related resource, the alert to cancel or update in this case. Template messages have predefined labels, so I wanted to send the alert id in the button payload, in order to extract it at the start of the conversation and proceed with the operation
But the challenges are: - The integration is not forwarding the payload correctly, it receives it in the handler but doesn't make it available in the
event
, looks like a bug tbh - The simplest workaround to get the alert id would be using
biz_opaque_callback_data
, but the handler doesn't forward it - And the last solution would be getting the id of the message that was replied to, which requires saving the ids to be found later which is cumbersome but doable, but we don't have access to that variable either
So my hands are tied 😕
What I'm doing atm is asking them again which alert they want to act on, but it's not a good ux since they just clicked it
f
Couple thoughts: 1. Is it not possible to save the alert ID in a user variable beforehand? Maybe I'm not understanding the use case correctly. 2. By design the integrations act as an adapter and not as a proxy, so they don't pass the payload as-is but as Botpress-specific payloads, so adding more data than currently available would be more of a feature request. 3. Doesn't seem to be mentioned in the docs but you indeed have access to the WA message ID, you can access it through
event.tags.message['whatsapp:id']
e
Thanks for your answer @famous-zoo-73118! 1. My bot sends template alerts letting users know that products they wanted are now available. They can click to see more details about the product, cancel or update the alert. But in order to find the product or the alert, I need the id that I'm sending in the Template Message payload, but it's not made available to the bot when the user replies. 2. I see, I will post the request then! 3. I was actually referring to the template message that gets replied to when the user clicks one of the actions, analogue to
slack:threadId
. I wanted to access it as a workaround to finding the alert
f
Regarding point 3, I think saving the
messages[0].context.id
in a conversation tag (e.g. "whatsapp::contextId") would be feasible. If you want to create a pull request with this change I'd be happy to bring attention to it so it's reviewed sooner 🙂
Otherwise I can also add it to our triage list and see if it can be worked on once current priorities allow!
e
Alright I’ll try to pull that
Hey @famous-zoo-73118 could you instruct me in how I would go about that? Appreciate it
What steps I need to take to make the context:id available as a tag
or the
biz_opaque_callback_data
available in the payload when the user interacts with a carousel
I'm gonna learn how to build integrations for this task
f
@early-train-33247 Yes, you can check this PR for reference: https://github.com/botpress/botpress/pull/12909/files
Note that you don't no longer need to prefix tag names with the integration name like it was done in https://github.com/botpress/botpress/pull/12909/files#diff-ffcfb05484d3bd423ecd8638085c28e1e11103edd2ea477962717b975e5ec5d6R3, so no need to create a constant as the integration client is already typed based on the tags you define in the integration.definition.ts file, so you can just reference the tag name directly when setting/getting it.
172 Views