Our Request to your Webhook URL
When an incoming message arrives at your Twilio phone number, Twilio sends a request to your web application via a webhook request. This request contains information about the incoming message, such as its sender and any attached media. Your application can store this data or use it for customizing a response, for example.
Twilio makes HTTP requests to your application, just like a regular web browser, in the format application/x-www-form-urlencoded
. By including parameters and values in its requests, Twilio sends data to your application that you can act upon before responding.
You can configure the URLs and HTTP Methods Twilio uses to make its requests via your account portal in the Twilio Console or using the REST API.
Please note: that Twilio cannot cache POSTs. If you want Twilio to cache static TwiML pages, then configure Twilio to make requests to your application using GET.
Parameters in Twilio's Request to your Application
When Twilio receives a message at one of your Twilio numbers or a WhatsApp-enabled number, it makes a synchronous HTTP request to the message URL configured for that number or Messaging Service and expects to receive TwiML in response.
Twilioはリクエストと一緒に下記のパラメーターを構成したHTTPメソッドに応じて、POSTパラメーターまたはURLクエリーパラメーターとして送信します。
リクエストパラメーター
パラメーター | 説明 | EXAMPLE |
---|---|---|
Message SID | このメッセージの 34 文字のユニークな識別子です。 後で REST API を使ってこのメッセージを取得する時に使えます。 | SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
SmsSid | MessageSidと同様の値。廃止される予定、後方互換のために用意されています。 | SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
AccountSid | このメッセージに関連付けられた アカウント の、34 文字の ID です。 | ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
MessagingServiceSid | The 34 character id of the Messaging Service associated with the message. | MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
From | このメッセージの送信された電話番号またはChannelアドレスです。 | +14017122661 |
To | 受信者の電話番号またはChannelアドレスです。 | +15558675310 |
Body | テキストの本文メッセージ。最大1600文字までです。 | "Ahoy! We can't wait to see what your build." |
NumMedia | メッセージに関連付けられたメディアアイテムの数です。 | 0 |
ReferralNumMedia | The number of media items associated with a "Click to WhatsApp" advertisement. | 0 |
Media-related Parameters
Twilio also sends the following parameters when there are media, such as images, associated with the incoming message:
パラメーター | 説明 | EXAMPLE |
---|---|---|
MediaContentType{N} | MediaUrl{N}に保存されたメディアのContentTypesです。 MediaContentType{N}の順番は、MediaUrl{N}の順番と一致します。 MediaContentType{N}が使用されるのではなく、NumMediaによって複数のメディア要素が含まれている場合、Nはメディアの0で始まるインデックス値となります(たとえば、MediaContentType0 となります)。 |
image/jpeg |
MediaUrl{N} | メッセージで受信されたメディアの内容を参照するURLです。 MediaContentType{N}が使用されるのではなく、NumMediaによって複数のメディア要素が含まれている場合、Nはメディアの0で始まるインデックス値となります(たとえば、MediaUrl0 となります。) |
|
Geographic Data-related Parameters
Twilioは From と To の電話番号から、場所の検索も行います。 次のパラメーターが存在する場合、Twlilio はこれらのパラメーターを送信します。
パラメーター | 説明 | EXAMPLE |
---|---|---|
FromCity | 送信者の都市名です。 | SAN FRANCISCO |
FromState | 送信者の州名です。 | CA |
FromZip | 送信者の郵便番号です。 | 94103 |
FromCountry | 送信者の国名です。 | US |
ToCity | 相手の都市名です。 | サウサリート |
ToState | 相手の州名です。 | CA |
ToZip | 相手の郵便番号です。 | 94965 |
ToCountry | 相手の国名です。 | US |
WhatsApp-specific Parameters
For WhatsApp messages, Twilio sends additional parameters:
パラメーター | 説明 | EXAMPLE |
ProfileName | The sender's WhatsApp profile name | Perspective Coffee |
WaId | The sender's WhatsApp ID (typically a phone number) | 14017122661 |
Forwarded | true if the message has been forwarded once |
true |
FrequentlyForwarded | true if the message has been frequently forwarded |
true |
ButtonText | The text of a Quick reply button | Cancel Appointment |
For incoming WhatsApp messages that share a location, Twilio includes the following parameters:
パラメーター | 説明 | EXAMPLE |
Latitude | Latitude value of location being sent | 51.51322977399644 |
Longitude | Longitude value of location being sent | -0.2197976373036567 |
住所 |
Address of location being sent |
187 Freston Road, London, Greater London W10 6TH |
label |
Label or name of location being sent |
The Harrow Club |
For incoming WhatsApp messages that originate from a "Click-to-WhatsApp" advertisement, Twilio includes the following parameters:
パラメーター | 説明 | EXAMPLE |
ReferralBody | Body text of the advertisement | Learn more about our company by sending us a message on WhatsApp |
ReferralHeadline | Headline text of the advertisement | Send us a message |
ReferralSourceId | Meta/WhatsApp's ID of the advertisement | 118588094077142 |
ReferralSourceType | The type of the advertisement | post |
ReferralSourceUrl | A URL referencing the content of the media shown in the advertisement when the user clicked to send a message | https://fb.me/xyz123 |
ReferralMediaId | Meta/WhatsApp's ID of the advertisement media shown when the users clicked to send a message; this will not match the Twilio Media SID | e420b130-f934-4acf-a5e6-f964f776bxyz |
ReferralMediaContentType | Media ContentType of the advertisement media shown to the user when the user clicked to send a message | image/jpeg |
ReferralMediaUrl | A URL referencing the media shown to the user in the advertisement | https://api.twilio.com/2010-04-01 /Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX /Messages/MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ Media/MEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
Status Callback Parameters
For status callbacks, Twilio also sends status-related parameters:
パラメーター | 説明 | EXAMPLE |
---|---|---|
MessageStatus | The status of the message. Can be: accepted , queued , sending , sent , failed , delivered , undelivered , receiving , received , or read (WhatsApp only). For more information, see detailed descriptions. |
delivered |
SmsStatus | Same as MessageStatus value. Deprecated and included for backward compatibility. | delivered |
ErrorCode callback on unsuccessful WhatsApp messages
If message delivery with WhatsApp fails, the SmsStatus
and MessageStatus
parameters will read undelivered
and Twilio will return Error 63016 as ErrorCode=63016
in the webhook response.
ヘルプが必要ですか?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.