This topic describes how to use the Payload parameter of a WhatsApp message template.
How Payload works
Payload is related to using a button to trigger a message in a WhatsApp message template.
For example, if a template has two quick_reply buttons and you pass [payload1,payload2], Chat App returns payload1 when the user clicks button 1. This lets you identify which button was clicked.
Parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
Payload |
array |
No |
The payload of the button. |
[payloadtext1,payloadtext2,payloadtext3] |
|
Payload |
string |
No |
The payload of the button in the message template. |
payloadtext1,payloadtext2,payloadtext3 |
Sample code
SendChatappMessageRequest sendChatappMessageRequest = new SendChatappMessageRequest();
sendChatappMessageRequest.setChannelType("whatsapp");
sendChatappMessageRequest.setFrom("****");
sendChatappMessageRequest.setTo("****");
sendChatappMessageRequest.setCustSpaceId("******");
sendChatappMessageRequest.setType(SendType.TEMPLATE.getName());
sendChatappMessageRequest.setLanguage("**");
sendChatappMessageRequest.setTemplateCode("*****");
Map<String, String> templateParams = new HashMap<>();
templateParams.put("variable1", "pre_auto1");
templateParams.put("variable2", "pre_auto2");
sendChatappMessageRequest.setTemplateParams(templateParams);
List<String> payload = new ArrayList<>();
payload.add("payload1");
payload.add("payload2");
sendChatappMessageRequest.setPayload(payload);
SendChatappMessageResponse sendChatappMessageResponse = ChatAppClient.instance().sendChatappMessage(sendChatappMessageRequest);
SendChatappMessageResponseBody body = sendChatappMessageResponse.getBody();
Sample response
{
"Context":{"from":"****","id":"****"},
"Type":"REPLY",
"Message":"{\"payload\":\"payload1\",\"text\":\"****\"}",
"CustSpaceId":"***",
"From":"***",
"To":"***",
"Timestamp":****,
"WabaId":"***",
"MessageId":"****",
"Name":"***"
}
References
SendChatappMassMessage -Batch Send Chat App Messages