Notification Resource
The Notification resource sends a notification to existing Bindings or a list of addresses.
You can notify users over these channels:
- APNS (iOS デバイス)
- Androidデバイス用のFCMおよびGCM
- SMSとMMS
- Facebook Messenger
Make sure you have consent from users before storing their device's address.
It’s a good practice to obtain your end users’ consent before you send them messages and some jurisdictions might require it by law.
We recommend that you consult with your legal counsel to make sure that your communications comply with all applicable laws.
To make sure your messages reach the right people, you should make sure that they have given you their consent to send them messages and that their contact information is current.
Check out the Twilio Marketplace for Add-ons from our partners that can help you keep your database up to date.
Notification properties
Names in REST API format | |
---|---|
sid
|
The unique string that we created to identify the Notification resource. |
account_sid
|
The SID of the Account that created the Notification resource. |
service_sid
|
The SID of the Service the resource is associated with. |
date_created
|
The date and time in GMT when the resource was created specified in RFC 2822 format. |
identities
|
The list of |
tags
|
The tags that select the Bindings to notify. Notifications will be attempted only to Bindings that have all of the tags listed in this property. |
segments
|
The list of Segments to notify. The Segment resource is deprecated. Use the |
priority
|
The priority of the notification. Can be: |
ttl
|
How long, in seconds, the notification is valid. Can be an integer between 0 and 2,419,200, which is 4 weeks, the default and the maximum supported time to live (TTL). Delivery should be attempted if the device is offline until the TTL elapses. Zero means that the notification delivery is attempted immediately, only once, and is not stored for future delivery. SMS does not support this property. |
title
|
The notification title. For FCM and GCM, this translates to the |
body
|
The notification text. For FCM and GCM, translates to |
sound
|
The name of the sound to be played for the notification. For FCM and GCM, this Translates to |
action
|
The actions to display for the notification. For APNS, translates to the |
data
|
The custom key-value pairs of the notification's payload. For FCM and GCM, this value translates to |
apn
|
The APNS-specific payload that overrides corresponding attributes in the generic payload for APNS Bindings. This property maps to the APNS |
gcm
|
The GCM-specific payload that overrides corresponding attributes in the generic payload for GCM Bindings. This property maps to the root JSON dictionary. Target parameters |
fcm
|
The FCM-specific payload that overrides corresponding attributes in the generic payload for FCM Bindings. This property maps to the root JSON dictionary. See the FCM documentation for more details. Target parameters |
sms
|
The SMS-specific payload that overrides corresponding attributes in the generic payload for SMS Bindings. Each attribute in this value maps to the corresponding |
facebook_messenger
|
Deprecated. |
alexa
|
Deprecated. |
Create a Notification resource
https://notify.twilio.com/v1/Services/{ServiceSid}/Notifications
Creating a Notification resource sends a notification to existing Bindings or to addresses provided in the request.
Send a Notification to existing Bindings
Set Identity
or Tag
to specify the stored Bindings to notify. To notify all available stored Bindings, set Tag
to all. If both Identity
and Tag
have values, only the Bindings that match both will be notified.
- Example 1 shows how to send a notification to a Binding identified by its
identity
. - Example 2 shows how to send a notification to a Binding identified by its
tags
. - Example 3 shows how to send a notification to a Binding identified by its
identity
and itstags
.
Send a Notification to Bindings in the request
Set ToBinding
to the JSON object that defines the Bindings to notify.
- Example 4 shows how to send a notification to Bindings defined in the request.
Send a Notification tailored to the specific channel
Define channel-specific features in the request to tailor the notification to the channel.
- Example 5 below shows how to apply channel-specific features to customize the notification content to the channel.
パラメーター
Names in REST API format | |
---|---|
service_sid
Path
|
The SID of the Service to create the resource under. |
body
オプション
|
The notification text. For FCM and GCM, translates to |
priority
オプション
|
The priority of the notification. Can be: |
ttl
オプション
|
How long, in seconds, the notification is valid. Can be an integer between 0 and 2,419,200, which is 4 weeks, the default and the maximum supported time to live (TTL). Delivery should be attempted if the device is offline until the TTL elapses. Zero means that the notification delivery is attempted immediately, only once, and is not stored for future delivery. SMS does not support this property. |
title
オプション
|
The notification title. For FCM and GCM, this translates to the |
sound
オプション
|
The name of the sound to be played for the notification. For FCM and GCM, this Translates to |
action
オプション
|
The actions to display for the notification. For APNS, translates to the |
data
オプション
|
The custom key-value pairs of the notification's payload. For FCM and GCM, this value translates to |
apn
オプション
|
The APNS-specific payload that overrides corresponding attributes in the generic payload for APNS Bindings. This property maps to the APNS |
gcm
オプション
|
The GCM-specific payload that overrides corresponding attributes in the generic payload for GCM Bindings. This property maps to the root JSON dictionary. See the GCM documentation for more details. Target parameters |
sms
オプション
|
The SMS-specific payload that overrides corresponding attributes in the generic payload for SMS Bindings. Each attribute in this value maps to the corresponding |
facebook_messenger
オプション
|
Deprecated. |
fcm
オプション
|
The FCM-specific payload that overrides corresponding attributes in the generic payload for FCM Bindings. This property maps to the root JSON dictionary. See the FCM documentation for more details. Target parameters |
segment
オプション
|
The Segment resource is deprecated. Use the |
alexa
オプション
|
Deprecated. |
to_binding
オプション
|
The destination address specified as a JSON string. Multiple |
delivery_callback_url
オプション
|
URL to send webhooks. |
identity
Required if tag is not passed
|
The |
tag
Required if identity is not passed
|
A tag that selects the Bindings to notify. Repeat this parameter to specify more than one tag, up to a total of 5 tags. The implicit tag |
例 1
例 2
例 3
例 4
例 5
ToBinding attributes
名前 | 概要 |
---|---|
binding_type | The channel to use. Possible values: sms , apn , gcm , fcm , facebook-messenger . |
address |
The destination address. For SMS, it is the phone number in E.164 format. For APNS, GCM and FCM, it is the device or registration token. For Facebook Messenger, it is the Messenger ID. |
Customize notification by channel
Notifications can be tailored to each notification channel to take advantage of channel-specific features or to customize the content to each channel.
The channel-specific payload of a notification can be provided by adding a parameter whose name is the BindingType and the value is the channel specific payload in a JSON object. Example 5 includes several such objects.
These channels support channel-specific payloads:
- APNS
- Fcm
- GCM
- SMS
- Facebook Messenger
The channel-specific content specified in this parameter can add a new property for the channel or replace the value in an existing property, but it cannot remove a property.
Example 5 sends a notification to all Bindings with Identity 00000001
. A generic Title
is specified and will be used for sms
binding and specifically for fcm
and apn
binding types a payload with title
and body
are also added, which will override the generic Title
.
Unrecoverable channel errors
When the underlying notification channel indicates an unrecoverable error, it is usually because there's a problem with the Binding. To ensure your database contains only valid Bindings, we delete the Bindings that return unrecoverable errors.
The following errors are unrecoverable.
Channel | error |
---|---|
APNS | APNS response status code 410 with error string "Unregistered" |
APNS | Address in invalid format |
GCM / FCM | Firebase response status code 200 + error:NotRegistered |
GCM / FCM | Firebase response status code 200 + error:InvalidRegistration |
GCM / FCM | Firebase response status code 200 + error:MismatchSenderId |
SMS | 21604 - 'To' phone number is blank |
Facebook Messenger | (has no unrecoverable errors) |
ヘルプが必要ですか?
誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。