詢問位置訊息

詢問位置訊息會顯示本文文字傳送位置按鈕。當 WhatsApp 用戶點擊該按鈕後會出現一個位置分享畫面,用戶接下來就可以使用這個畫面分享自己的位置。


用戶分享自己的位置後,系統將觸發訊息 Webhook,其中包含用戶的位置詳細資訊。

傳送詢問位置訊息

使用 POST /<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>/messages 端點傳送詢問位置訊息給 WhatsApp 用戶。

要求語法

POST /<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>/messages

張貼內容

{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "type": "interactive",
  "to": "<WHATSAPP_USER_PHONE_NUMBER>",
  "interactive": {
    "type": "location_request_message",
    "body": {
      "text": "<BODY_TEXT>"
    },
    "action": {
      "name": "send_location"
    }
  }
}

張貼內容參數

預留位置說明範例值

<BODY_TEXT>

字串

必要項目。

訊息內文。支援網址。

最多 1024 個字元。

Let's start with your pickup. You can either manually *enter an address* or *share your current location*.

<WHATSAPP_USER_PHONE_NUMBER>

String

Required.

WhatsApp user phone number.

+16505551234

回應

成功後:

{
  "messaging_product": "whatsapp",
  "contacts": [
    {
      "input": "<WHATSAPP_USER_PHONE_NUMBER>",
      "wa_id": "<WHATSAPP_USER_ID>"
    }
  ],
  "messages": [
    {
      "id": "<WHATSAPP_MESSAGE_ID>",
      "message_status": "<PACING_STATUS>"
    }
  ]
}

回應內容

PlaceholderDescriptionSample Value

<WHATSAPP_USER_PHONE_NUMBER>

String

WhatsApp user's WhatsApp phone number. May not match wa_id value.

+16505551234

<WHATSAPP_USER_ID>

String

WhatsApp user's WhatsApp ID. May not match input value.

16505551234

<WHATSAPP_MESSAGE_ID>

String

WhatsApp Message ID. This ID appears in associated messages webhooks, such as sent, read, and delivered webhooks.

wamid.HBgLMTY0NjcwNDM1OTUVAgARGBI4MjZGRDA0OUE2OTQ3RkEyMzcA

<PACING_STATUS>

String

Indicates template pacing status. The message_status property is only included in responses when sending a template message that uses a template that is being paced.

wamid.HBgLMTY0NjcwNDM1OTUVAgARGBI4MjZGRDA0OUE2OTQ3RkEyMzcA

Webhook

當 WhatsApp 用戶分享自己的位置來回應您的訊息時,系統會觸發訊息 Webhook,其中包含用戶的位置詳細資訊。

{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "<WHATSAPP_BUSINESS_ACCOUNT_ID>",
      "changes": [
        {
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "<WHATSAPP_BUSINESS_DISPLAY_PHONE_NUMBER>",
              "phone_number_id": "<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>"
            },
            "contacts": [
              {
                "profile": {
                  "name": "<WHATSAPP_USER_NAME>"
                },
                "wa_id": "<WHATSAPP_USER_ID>"
              }
            ],
            "messages": [
              {
                "context": {
                  "from": "<WHATSAPP_BUSINESS_PHONE_NUMBER>",
                  "id": "<WHATSAPP_CONTEXT_MESSAGE_ID>"
                },
                "from": "<WHATSAPP_USER_ID>",
                "id": "<WHATSAPP_MESSAGE_ID>",
                "timestamp": "<TIMESTAMP>",
                "location": {
                  "address": "<LOCATION_ADDRESS>",
                  "latitude": <LOCATION_LATITUDE>,
                  "longitude": <LOCATION_LONGITUDE>,
                  "name": "<LOCATION_NAME>"
                },
                "type": "location"
              }
            ]
          },
          "field": "messages"
        }
      ]
    }
  ]
}

Webhook 內容

預留位置說明範例值

<LOCATION_ADDRESS>

字串

位置地址。

只有當 WhatsApp 用戶選擇分享此參數時,才會顯示。

1071 5th Ave, New York, NY 10128

<LOCATION_LATITUDE>

數字

位置緯度(以十進制度數為單位)。

40.782910059774

<LOCATION_LONGITUDE>

數字

位置經度(以十進制度數為單位)。

-73.959075808525

<LOCATION_NAME>

字串

位置名稱。

只有當 WhatsApp 用戶選擇分享此參數時,才會顯示。

Solomon R. Guggenheim Museum

<TIMESTAMP>

字串

UNIX 時間戳記,指示我們的伺服器何時處理 WhatsApp 用戶的訊息。

1702920965

<WHATSAPP_BUSINESS_ACCOUNT_ID>

字串

WhatsApp Business 帳號編號。

102290129340398

<WHATSAPP_BUSINESS_DISPLAY_PHONE_NUMBER>

字串

WhatsApp Business 電話號碼的顯示號碼。

15550783881

<WHATSAPP_BUSINESS_PHONE_NUMBER>

字串

WhatsApp Business 電話號碼。

15550783881

<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>

字串

WhatsApp Business 電話號碼編號。

106540352242922

<WHATSAPP_CONTEXT_MESSAGE_ID>

字串

用戶回覆中之訊息的 WhatsApp 訊息編號。

wamid.HBgLMTY0NjcwNDM1OTUVAgARGBI1QjJGRjI1RDY0RkE4Nzg4QzcA

<WHATSAPP_MESSAGE_ID>

字串

用戶訊息的 WhatsApp 訊息編號。

wamid.HBgLMTY0NjcwNDM1OTUVAgASGBQzQTRCRDcwNzgzMTRDNTAwRTgwRQA=

<WHATSAPP_USER_ID>

字串

WhatsApp 用戶的 WhatsApp 編號。

16505551234

<WHATSAPP_USER_NAME>

字串

WhatsApp 用戶的名稱。

Pablo Morales

要求範例

curl 'https://graph.facebook.com/v21.0/106540352242922/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "type": "interactive",
  "to": "+16505551234",
  "interactive": {
    "type": "location_request_message",
    "body": {
      "text": "Let us start with your pickup. You can either manually *enter an address* or *share your current location*."
    },
    "action": {
      "name": "send_location"
    }
  }
}'

回應範例

{
  "messaging_product": "whatsapp",
  "contacts": [
    {
      "input": "+16505551234",
      "wa_id": "16505551234"
    }
  ],
  "messages": [
    {
      "id": "wamid.HBgLMTY0NjcwNDM1OTUVAgARGBJCNUQ5RUNBNTk3OEQ2M0ZEQzgA"
    }
  ]
}

Webhook 範例

{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "102290129340398",
      "changes": [
        {
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "15550783881",
              "phone_number_id": "106540352242922"
            },
            "contacts": [
              {
                "profile": {
                  "name": "Pablo Morales"
                },
                "wa_id": "16505551234"
              }
            ],
            "messages": [
              {
                "context": {
                  "from": "15550783881",
                  "id": "wamid.HBgLMTY0NjcwNDM1OTUVAgARGBI1QjJGRjI1RDY0RkE4Nzg4QzcA"
                },
                "from": "16505551234",
                "id": "wamid.HBgLMTY0NjcwNDM1OTUVAgASGBQzQTRCRDcwNzgzMTRDNTAwRTgwRQA=",
                "timestamp": "1702920965",
                "location": {
                  "address": "1071 5th Ave, New York, NY 10128",
                  "latitude": 40.782910059774,
                  "longitude": -73.959075808525,
                  "name": "Solomon R. Guggenheim Museum"
                },
                "type": "location"
              }
            ]
          },
          "field": "messages"
        }
      ]
    }
  ]
}