# Quick replies, button, generic at media template sa Messenger

> Magpadala ng quick replies at button, generic at media template sa Messenger, kasama ang mga limit nila, at i-route ang tap sa quick reply at postback sa iisang Python webhook.

Published 2026-11-04. Z-API Omni team.

Umaabot sa webhook mo ang tap sa quick reply bilang `messages` event, na nasa `message.quick_reply.payload` ang payload mo at nasa `message.text` ang title ng button. Dumarating naman ang tap sa postback button bilang `messaging_postbacks` event na nasa `postback.payload` ang payload. Ganoon din ang Get Started button at ang mga item ng persistent menu. I-subscribe ang Page mo sa dalawang field, kung hindi ay may isang uri ng tap na hindi kailanman aabot sa server mo. Lahat ng apat na uri ng mensahe sa ibaba ay ipinapadala sa pamamagitan ng POST sa `https://graph.facebook.com/v26.0/me/messages` gamit ang Page access token.

## Mga limit ng bawat uri ng mensahe

Ito ang mga limit na nakasulat ng Meta sa bawat page, lahat na-access noong 2026-11-04: [quick replies](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/quick-replies), [button template](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/template/button), [generic template](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/template/generic), [media template](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/template/media), [postback button](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/buttons/postback) at [URL button](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/buttons/url).

| Element | Limit | Dumarating ang tap bilang |
| --- | --- | --- |
| Quick replies | 13 kada mensahe; `title` 20 character; `payload` 1,000 character; `image_url` hindi bababa sa 24 x 24 px | `messages` |
| Button template | `text` hanggang 640 character; 1 hanggang 3 button | `messaging_postbacks` (mga postback button) |
| Generic template | Hanggang 10 element; `title` at `subtitle` 80 character bawat isa; 3 button kada element | `messaging_postbacks` (mga postback button) |
| Media template | 1 element, image o video lang; 3 button | `messaging_postbacks` (mga postback button) |
| Postback button | `title` 20 character; `payload` 1,000 character | `messaging_postbacks` |
| URL button | `title` 20 character | Binubuksan ang URL; hindi nagti-trigger ng `messaging_postbacks` |

Nagbabalik ng `recipient_id` at `message_id` ang bawat pagpapadala ng template. Ipinapaliwanag ang token, ang subscription ng Page at ang unang text message sa [pag-set up ng Messenger Send API](/academy/fil/articles/messenger-platform-send-api-setup-page-token/).

## Magpadala ng quick replies

Nagta-tap ang user sa quick reply sa halip na mag-type. Inaalis ng tap ang mga button at ipinopost ang title sa thread bilang mensahe ng user. Sinasabi ng best-practice note ng Meta na "Nawawala ang quick replies pagkatapos ng susunod na mensahe", kaya ilagay ang mga pangmatagalang aksyon sa [persistent menu](/academy/fil/articles/messenger-persistent-menu-get-started-button/).

Ito ang sample ng Meta na nilagyan ng value ang mga placeholder payload at inilipat sa HTTPS ang mga image URL.

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": { "id": "PSID" },
  "messaging_type": "RESPONSE",
  "message": {
    "text": "Pick a color:",
    "quick_replies": [
      { "content_type": "text", "title": "Red", "payload": "PICK_RED", "image_url": "https://example.com/img/red.png" },
      { "content_type": "text", "title": "Green", "payload": "PICK_GREEN", "image_url": "https://example.com/img/green.png" }
    ]
  }
}' "https://graph.facebook.com/v26.0/me/messages?access_token=PAGE_ACCESS_TOKEN"
```

Kailangan ng `text` quick reply ang `title` at `payload`. Puwedeng walang lamang string ang `payload` kapag naka-set ang `image_url`, at required ang `image_url` kapag walang laman ang `title`. Dapat ding may `text` o `attachment` ang `message`. Ang mas malalaking image ay "awtomatikong kino-crop at nire-resize."

May dalawa pang content type na humihingi ng contact data: `{ "content_type": "user_phone_number" }` at `{ "content_type": "user_email" }`. Pinupunan ito ng Messenger mula sa profile ng tao at itinatago ang button kapag wala ang value sa profile. Bumabalik ang value sa `quick_reply.payload` at sa `text`. Idinadagdag ng Meta na ang pagpili rito ay "ipinapadala ang impormasyon nang isang beses at hindi ito pahintulot na i-access ang impormasyon sa hinaharap."

## Magpadala ng button template

Ang button template ay text na hanggang 640 character na may isa hanggang tatlong button sa ilalim. Pinagsasama ng body na ito ang `web_url` sample ng Meta mula sa page ng button template at ang `postback` button mula sa page ng postback button, na pinalitan ang title at payload ng postback.

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": { "id": "PSID" },
  "message": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "button",
        "text": "What do you want to do next?",
        "buttons": [
          { "type": "web_url", "url": "https://www.messenger.com", "title": "Visit Messenger" },
          { "type": "postback", "title": "Talk to us", "payload": "TALK_TO_US" }
        ]
      }
    }
  }
}' "https://graph.facebook.com/v26.0/me/messages?access_token=PAGE_ACCESS_TOKEN"
```

Anim na uri ang nakalista sa [buttons overview](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/buttons) ng Meta: `web_url`, `postback`, `phone_number`, `account_link`, `account_unlink` at `game_play`. Nagbubukas ang URL button sa webview ng Messenger. Tumatanggap ang `webview_height_ratio` ng `compact`, `tall` o `full`, at `full` ang default. Kapag naka-`true` ang `messenger_extensions`, dapat HTTPS ang URL at dapat nasa `whitelisted_domains` ng Messenger Profile ang domain nito. Inaalis ng `webview_share_button: "hide"` ang share button para sa mga page na nagpapakita ng pribadong data.

## Magpadala ng generic template carousel

Ang generic template ay card na may image, title, subtitle at hanggang tatlong button. Maglagay ng hanggang 10 card sa `elements` at ipapakita ito ng Messenger bilang pahalang na carousel. Tumatakbo ang sample ng Meta gaya ng pagkakalathala nito.

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": { "id": "PSID" },
  "message": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "generic",
        "elements": [
          {
            "title": "Welcome!",
            "image_url": "https://raw.githubusercontent.com/fbsamples/original-coast-clothing/main/public/styles/male-work.jpg",
            "subtitle": "We have the right hat for everyone.",
            "default_action": {
              "type": "web_url",
              "url": "https://www.originalcoastclothing.com/",
              "webview_height_ratio": "tall"
            },
            "buttons": [
              { "type": "web_url", "url": "https://www.originalcoastclothing.com/", "title": "View Website" },
              { "type": "postback", "title": "Start Chatting", "payload": "DEVELOPER_DEFINED_PAYLOAD" }
            ]
          }
        ]
      }
    }
  }
}' "https://graph.facebook.com/v26.0/me/messages?access_token=PAGE_ACCESS_TOKEN"
```

Kailangan ng bawat element ang kahit isang property bukod sa `title`. Tumatanggap ang `default_action` ng mga field ng URL button maliban sa `title` at nagbubukas kapag tinap ng tao ang mismong card. "Sina-scale o kino-crop ng Messenger ang mga photo sa generic template na hindi 1.91:1", kaya i-crop ang mga image mo sa ratio na iyon bago ipadala. Lumalabas ang mga GIF pero hindi gumagalaw. I-set ang `sharable: true` sa payload para ipakita ang native na share button.

Pinapayo rin ng Meta na unahin ang pinakamahalagang card, dahil hindi laging nag-i-scroll ang mga tao hanggang dulo. Walang ibinibigay na maximum na laki ng image o file format para sa mga card ang page ng Meta.

## Magpadala ng media template

Nagpapadala ang media template ng isang image o isang video na may hanggang tatlong button. Hindi suportado ang audio. Sinasabi ng page ng Meta na "Hindi pinapayagan ng media template ang anumang external URL, mga Facebook URL lang." Apat na hugis ng URL ang tinatanggap nito: `business.facebook.com/PAGE_NAME/videos/ID`, `www.facebook.com/USERNAME/videos/ID/`, `business.facebook.com/PAGE_NAME/photos/ID` at `www.facebook.com/photo.php?fbid=ID`. Para sa anumang ibang file, i-upload muna ito at ipadala ang `attachment_id`.

Kinukuha ng [Attachment Upload API](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/saving-assets) (na-access noong 2026-11-04) ang file mula sa URL mo at nagbabalik ng `{"attachment_id": "..."}`. Gumagamit ang sample ng Meta ng v2.10 at HTTP URL. Parehong in-update dito.

```bash
curl -X POST "https://graph.facebook.com/v26.0/me/message_attachments?access_token=PAGE_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "attachment": {
        "type": "image",
        "payload": { "url": "https://example.com/image.jpg", "is_reusable": true }
      }
    }
  }'
```

Saka ipadala ang template gamit ang ID na iyon. Gamitin ang `"media_type": "video"` para sa video.

```bash
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": { "id": "PSID" },
  "message": {
    "attachment": {
      "type": "template",
      "payload": {
        "template_type": "media",
        "elements": [ { "media_type": "image", "attachment_id": "ATTACHMENT_ID" } ]
      }
    }
  }
}' "https://graph.facebook.com/v26.0/me/messages?access_token=PAGE_ACCESS_TOKEN"
```

Hindi puwedeng magkasama ang `attachment_id` at `url`, at hindi gumagana ang mga attachment ID para sa media mula sa mga Facebook URL. "Nag-e-expire ang mga attachment ID pagkalipas ng 90 araw", kaya i-upload ulit ang anumang paulit-ulit mong ipinapadala. Tumatanggap ang upload ng hanggang 8 MB para sa mga image at 25 MB para sa ibang file, pagkatapos ng encoding. Nagta-time out ang pagkuha ng Meta pagkalipas ng 75 segundo para sa video at 10 segundo para sa ibang file, kaya i-host ang file sa mabilis na lugar.

## I-route ang quick replies at postback sa iisang webhook

Parehong gumagamit ng `entry[].messaging[]` na envelope ang dalawang event, kaya kayang paghiwalayin sila ng iisang loop. Ang `postback` key ay nangangahulugang tap sa button, Get Started o menu. Ang `message` na may `quick_reply` key ay tap sa quick reply. Ang `message` na `text` lang ang laman ay tinype na input ([quick replies](https://developers.facebook.com/documentation/business-messaging/messenger-platform/send-messages/quick-replies), [messaging_postbacks](https://developers.facebook.com/documentation/business-messaging/messenger-platform/webhooks/webhook-events/messaging_postbacks), [webhooks](https://developers.facebook.com/documentation/business-messaging/messenger-platform/webhooks), na-access noong 2026-11-04).

Tumatakbo ang router sa ibaba sa Python 3.9 o mas bago gamit ang standard library. Mga sample ng Meta ang dalawang test body nito. Galing ang para sa quick reply sa page ng quick replies, at ang para sa postback sa page ng webhooks, na isinulat bilang ordinaryong string ang mga placeholder na naka-angle bracket.

```python
import json

QUICK_REPLY_SAMPLE = """{"object": "page", "entry": [{"id": "PAGE_ID", "time": 1502905976963, "messaging": [
  {"sender": {"id": "1254459154682919"}, "recipient": {"id": "682498171943165"}, "timestamp": 1502905976377,
   "message": {"quick_reply": {"payload": "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN"},
               "mid": "m_AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdCK48PnKAjSdjfipqxqMvK8ma6AC8fplwlqLP_5cgXIbu7I3rBN0P",
               "text": "Green"}}]}]}"""

POSTBACK_SAMPLE = """{"object": "page", "entry": [{"id": "PAGE_ID", "time": 1458692752478, "messaging": [
  {"sender": {"id": "PSID"}, "recipient": {"id": "PAGE_ID"}, "timestamp": 1458692752478,
   "postback": {"title": "BUTTON_TITLE", "payload": "DEVELOPER_DEFINED_PAYLOAD"}}]}]}"""

seen_mids = set()  # in memory for the demo; use a database table in production

def classify(event):
    if "postback" in event:
        postback = event["postback"]
        return "postback", postback.get("payload"), postback.get("title")
    message = event.get("message") or {}
    if "quick_reply" in message:
        return "quick_reply", message["quick_reply"].get("payload"), message.get("text")
    if "text" in message:
        return "text", None, message["text"]
    return "other", None, None

def route(body):
    events = [e for entry in body.get("entry", []) for e in entry.get("messaging", [])]
    events.sort(key=lambda e: e.get("timestamp", 0))  # Meta may deliver out of order
    results = []
    for event in events:
        mid = (event.get("message") or event.get("postback") or {}).get("mid")
        if mid in seen_mids:
            continue  # a retried delivery
        if mid:
            seen_mids.add(mid)
        kind, payload, title = classify(event)
        results.append((event["sender"]["id"], kind, payload, title))
    return results

if __name__ == "__main__":
    for sample in (QUICK_REPLY_SAMPLE, POSTBACK_SAMPLE):
        print(route(json.loads(sample)))
```

Nagpi-print ito ng isang tuple kada event: PSID ng sender, kind, payload at title. Mag-dispatch muna sa `kind` at saka sa `payload`. Magkaibang event pa rin ang quick reply at postback button na may parehong payload string.

Itinatakda ng webhook page ng Meta ang mga patakaran sa paligid ng code na ito. Ang endpoint mo ay "dapat magbalik ng `200 OK` na response" sa loob ng 5 segundo o mas maikli. Inuulit ang mga pumalyang delivery, kaya nilalaktawan ng router ang `mid` na nakita na nito. Puwedeng dumating nang hindi magkakasunod ang mga event, kaya may sort sa `timestamp`.

Pagkatapos ng isang oras ng mga pagpalya, ina-unsubscribe ng Meta ang app. Suriin ang `X-Hub-Signature-256` sa raw body bago mo ito i-parse, gaya ng inilalarawan sa [pag-verify ng webhook signature](/academy/fil/articles/whatsapp-webhook-signature-verification-x-hub-signature-256/), dahil pumipirma ang Messenger gamit ang parehong App Secret HMAC. Para sa dedupe table na nananatili kahit mag-restart, tingnan ang [idempotent na paghawak ng webhook](/academy/fil/articles/n8n-duplicate-webhooks-idempotency/).

Ang `postback.payload` ay "kasama lang sa webhook notification na ipinadala sa app na nagpadala ng mensahe sa tao." Kung maraming app ang naghahati sa isang Page, ang app na nagpadala ng template lang ang nakakakita ng payload. Lumalabas lang ang `postback.referral` object kapag nagsimula ang usapan mula sa m.me link, Click to Messenger ad, Messenger QR code o sa welcome screen.

*Ang Z-API Omni team*
