Postback buttons are a great way to enhance your conversations because they can trigger server-side logic when a user clicks on them. When you send the postback button, you can attach a payload and when the user clicks on it, it will trigger webhooks listening to the postback trigger. The payload associated with the action clicked by the user will be included in the webhook body. This allows you to respond to the press of a button from your backend. The server-side logic can use the payload to run different code based on the context of the conversation. These features are very useful when building a bot. You can also use them to trigger other server-side actions with the click of a button in the conversation, such as an “add-to-cart” action.

Sending postback buttons

Postback buttons can be leveraged by the Zendesk bot builder in carousel messages, so you can create carousel buttons for your Zendesk bot that save the user's response and proceed with the flow accordingly. You can also send postback buttons by using the Sunshine Conversations Post Message API. A Zendesk Suite Professional plan or above is required to send the postback buttons with the Sunshine Conversations API.

You can use postback buttons together with other button types in the same message, as shown below, with the exception of reply buttons. Reply buttons can not be used together with postback buttons or any other button type supported in messaging.

const apiInstance = new SunshineConversationsApi.MessagesApi();const data = new SunshineConversationsApi.MessagePost();data.author = {    type: 'business'};data.content = {    type: 'text',    text: 'Press one of the buttons below',    actions: [        {            type: 'postback',            text: 'Postback Button Label',            payload: 'PAYLOAD_HERE'        },        {            type: 'link',            text: 'Link Button Label',            uri: 'http://url.button.com'        }    ]};
apiInstance.postMessage(appId, conversationId, data)    .then(response => /* success */)    .catch(error => /* failure */);

Setting up your conversation integrations

When sending postback buttons through the Sunshine Conversations API, setting up “conversation integrations” and subscribing to postback events is required for the buttons to trigger webhooks. See Creating conversations integrations in Admin Center for more information.

Echo postbacks

The ‘echoPostback’ allows you to add a message to the conversation history when a postback button is clicked. The content of the message will match the button label. When ‘echoPostback’ is enabled, the message is silently added to the conversation as a user message, without a corresponding ‘conversation:message’ webhook being triggered. To enable ‘echoPostback’, you must make an updateApp request to update the app with the Sunshine Conversations API.