Coupon Template |
This document describes how to create and send a coupon to a person in a Messenger conversation.
How It WorksA coupon template message has some preset elements and a number of optional properties. The title for the message recipient is required and gives the recipient details about the coupon. The disclaimer, Terms may apply., is a preset element but can be configured. The Reveal code button is a preset element that can not be changed. You can add a second button, with default text Shop now, that is configurable with your own text and a URL to redirect a person to your store. |
When a person clicks the Reveal code button, the coupon code is displayed in the conversation and a webhook notification is sent to your server.
Este guia considera que você leu a Overview for the Messenger Platform e implementou os componentes necessários para enviar e receber mensagens e notificações.
You need the following:
pages_show_list
and pages_messaging
permissionsmessages
webhookIn the following example, we are sending a basic coupon message that contains a coupon code.
To send a coupon message, send a POST
request to the /PAGE-ID/messages
endpoint with a JSON object with the attachment type set to template
and payload set with the template_type
set to coupon
, title
set to coupon text, and the coupon_code
set to the coupon code to send to the person.
In the following code example we have set The subtitle text, Terms may apply., and Reveal code button text are the default text for these coupon message properties. |
curl -X POST -H "Content-Type: application/json" -d '{ "recipient":{ "id":"PSID" }, "message":{ "attachment": { "type": "template", "payload": { "template_type": "coupon", "title":"10% off everything", "coupon_code":"10PERCENT", }, } } }' "https://graph.facebook.com/LATEST-API-VERSION/PAGE-ID/messages?access_token=PAGE-ACCESS-TOKEN"
On success, your app receives the following JSON response with the PSID for the recipient and the ID for the message:
{ "recipient_id": "PSID", "message_id": "MESSAGE-ID" }
Send a Complex CouponIn the following example, we are sending a more complex coupon message that contains all the properties you can send in the coupon template payload. In the following code example we have configured a greeting using the |
curl -X POST -H "Content-Type: application/json" -d '{ "recipient":{ "id":"PSID" }, "message":{ "attachment": { "type": "template", "payload": { "template_type": "coupon", "title":"10% off everything", "subtitle":"10% off. Limit 1 per customer. Expires on October 1st, 2022", "coupon_code":"10PERCENT", "coupon_url":"https://www.myshop.com/", "coupon_url_button_title":"Shop now", "coupon_pre_message":"Here'\''s a deal just for you!", "image_url": "https://www.myshop.com/sale-image.png", "payload":"The coupon for 10% off everything that expires 2022-10-1", }, } } }' "https://graph.facebook.com/LATEST-API-VERSION/PAGE-ID/messages?access_token=PAGE-ACCESS-TOKEN"
On success, your app receives the following JSON response with the PSID for the recipient and the ID for the message:
{ "recipient_id": "PSID", "message_id": "MESSAGE-ID" }
When a person clicks on the coupon message, a messages
webhook notification is sent to your server. The notification will contain the PSID for the person who clicked the coupon message, the ID for the Page that sent the message, and payload information about the coupon.
{ "sender": { "id": "PSID", }, "recipient": { "id": "PAGE-ID", }, "timestamp": UNIX-TIMESTAMP, "template": { "type" : "coupon", "payload" : "ADDITIONAL-INFORMATION", "coupon_code":"COUPON-CODE", } }
Property | Description |
---|---|
| Required. Object containing information about the person receiving the coupon message |
id string | The Page-scoped ID (PSID) for the person receiving the coupon message |
comment_id string | Send a Private Reply that contains a coupon template to a person who commented on a post on the Facebook Page |
notification_message_token string | Send Marketing Messages that contain a coupon template to a person |
post_id string | Send a Private Reply that contains a coupon template to a person who published a visitor post on the Facebook Page |
user_ref string | Send a Checkbox plugin or Customer Chat plugin that contains a coupon template |
message object | Required. Contains the attachment object |
attachment object | Required. Contains the type of message and payload. |
type enum { template } | Required. Message type, set to |
payload object | Required. Contains the message coupon details |
template_type enum { coupon } | Required. Set to |
title string | Required. Title to display in the message. 80 character limit. |
subtitle string | Subtitle to display in the message. 80 character limit. |
coupon_code string | Required unless |
coupon_pre_message string | The message sent before the coupon message |
coupon_url string | Required unless |
coupon_url_button_title string | The text for the button that allows a person to click to the coupon URL |
image_url string | The URL for the image displayed in the coupon message |
payload string | Additional information to be included in the webhook notification |