互動式訊息範本將您可傳送給收件人的內容擴充至標準訊息範本和媒體訊息範本類型之外,以包含使用 components
物件的互動式按鈕。
系統提供兩種類型的預訂按鈕:
這些按鈕可以附加至文字訊息或媒體訊息。互動式訊息範本建立並通過核准後,即可用於通知訊息以及顧客服務/關懷訊息中。
您需要:
當訊息範本獲得核准後,您就可以使用 API 傳送訊息。
/messages
發出 POST
呼叫POST /v1/messages { "to": "recipient_wa_id", "type": "template", "template": { "namespace": "your-namespace", "language": { "policy": "deterministic", "code": "your-language-and-locale-code" }, "name": "your-template-name", "components": [ { "type" : "header", "parameters": [ { "type": "text", "text": "replacement_text" } ] # end header }, { "type" : "body", "parameters": [ { "type": "text", "text": "replacement_text" }, { "type": "currency", "currency" : { "fallback_value": "$100.99", "code": "USD", "amount_1000": 100990 } }, { "type": "date_time", "date_time" : { "fallback_value": "February 25, 1977", "day_of_week": 5, "day_of_month": 25, "year": 1977, "month": 2, "hour": 15, "minute": 33, #OR "timestamp": 1485470276 } }, { ... # Any additional template parameters } ] # end body }, # The following part of this code example includes several possible button types, # not all are required for an interactive message template API call. { "type": "button", "sub_type" : "quick_reply", "index": "0", "parameters": [ { "type": "payload", # Business Developer-defined payload "payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT" } ] }, { "type": "button", "sub_type" : "url", "index": "1", "parameters": [ { "type": "text", # Business Developer-defined dynamic URL suffix "text": "9rwnB8RbYmPF5t2Mn09x4h" } ] }, { "type": "button", "sub_type" : "url", "index": "2", "parameters": [ { "type": "text", # Business Developer-defined dynamic URL suffix "text": "ticket.pdf" } ] } ] } }
成功的回應會包含一個有 id
的 messages
物件。
{ "messages": [{ "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU" }] }
不成功的回應則會包含一個錯誤物件,其中包含錯誤字串、錯誤代碼以及其他資訊。
如果將範本發送到無法接收該範本的帳號,系統會將 1026 (ReceiverIncapable)
錯誤以錯誤物件的方式發送到已設定的 Webhook 伺服器。
如需有關錯誤的詳細資訊,請參閱錯誤和狀態代碼。
當用戶點擊快速回覆按鈕時,系統會將 responjse 傳回給商家。請參閱快速回覆按鈕點擊次數的回呼以取得資訊。用戶也可以選擇不點擊按鈕,而只向您傳送自由格式的訊息。
{ "contacts": [ { "profile": { "name": "Kerry Fisher" }, "wa_id": "16505551234" } ], "messages": [ { "button": { "payload": "No-Button-Payload", "text": "No" }, "context": { "from": "16315558007", "id": "gBGGFmkiWVVPAgkgQkwi7IORac0" }, "from": "16505551234", "id": "ABGGFmkiWVVPAgo-sKD87hgxPHdF", "timestamp": "1591210827", "type": "button" } ] # If there are any errors, an errors field (array) will be present "errors": [ { ... } ] }
這些範例說明設定互動式訊息範本的程序,從在企業管理平台中建立範本開始,並透過 API 呼叫將訊息範本發送到 messages
端點。
此範例說明如何建立含有快速回覆按鈕的互動式媒體訊息範本。
messages
API 呼叫新增在參數資訊中。POST /v1/messages { "to": "your-test-recipient-wa-id", "recipient_type": "individual", "type": "template", "template": { "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2", "name": "upcoming_trip_reminder", "language": { "code": "en", "policy": "deterministic" }, "components": [ { "type": "header", "parameters": [ { "type": "text", "text": "12/26" } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "*Ski Trip*" }, { "type": "date_time", "date_time" : { "fallback_value": "29th July 2019, 8:00am", "day_of_month": "29", "year": "2019", "month": "7", "hour": "8", "minute": "00" } }, { "type": "text", "text": "*Squaw Valley Ski Resort, Tahoe*" } ] }, { "type": "button", "sub_type": "quick_reply", "index": 0, "parameters": [ { "type": "payload", "payload": "Yes-Button-Payload" } ] }, { "type": "button", "sub_type": "quick_reply", "index": 1, "parameters": [ { "type": "payload", "payload": "No-Button-Payload" } ] } ] } }
此範例說明如何建立含有網址和電話號碼按鈕的互動式媒體訊息範本。
messages
API 呼叫新增在參數資訊中。POST /v1/messages { "to": "your-test-recipient-wa-id", "recipient_type": "individual", "type": "template", "template": { "namespace": "88b39973_f0d5_54e1_29cf_e80f1e3da4f2", "name": "oculus_shipment_update", "language": { "code": "en", "policy": "deterministic" }, "components": [ { "type": "header", "parameters": [{ "type": "image", "image": { "link": "link-to-your-image" } }] }, { "type": "body", "parameters": [ { "type": "text", "text": "Anand" }, { "type": "text", "text": "Quest" }, { "type": "text", "text": "113-0921387" }, { "type": "date_time", "date_time" : { "fallback_value": "23rd Nov 2019", "day_of_month": "20", "year": "2019", "month": "9" } } ] }, { "type": "button", "index": "0", "sub_type": "url", "parameters": [ { "type": "text", "text": "1Z999AA10123456784" } ] } ] } }