Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

プッシュ通知の構成

Programmable Chat integrates APN (iOS) and GCM/FCM (Android and browsers) Push Notifications for certain events. Not all implementations need every possible event to trigger push notifications. Additionally, the content and payload of your push notifications will differ based on requirements and use cases.

Chat Service instances provide some configuration options which allow push configuration on a per Service instance basis. These options allow for:

  • 条件を満たしたチャットイベントのいずれがプッシュ通知をトリガーすべきか選択する
  • 各メッセージタイプごとのペイロード・テンプレートの記述(既定のテンプレートの上書き)

It is not currently possible to selectively register for various push notification message types on the client SDKs (iOS and Android). This capability is planned and will be delivered in a future release of the relevant SDKs.

目次

プッシュ通知の種類

The following Push Notifications can be configured for a Chat Service instance:

プッシュ通知の種類 概要
New Message チャネルに新しいメッセージが送信されたときにチャネル内の全メンバーに送信されます
Added to Channel チャネルに追加されたユーザーに送信されます
Invited to Channel チャネル参加を招待されたユーザーに送信されます
Removed from Channel それまで在籍していたチャネルから削除されたユーザーに対して送信されます

Note: The default enabled flag for new Service instances for all Push Notifications is false. This means that Push will be disabled until you explicitly enable it.

Note: You may configure a sound parameter value for each of the Push Notification types (detailed below).

プッシュ通知のテンプレート

Each of the Push Notification types has a default template for the payload (or notification body). Each of these templates can be overridden per Service instance via the Push Notification configuration. The templating employs very simple markup for a limited set of variables:

テンプレート変数

テンプレート変数 概要
${USER} Will be replaced with the FriendlyName of the User who triggered the Push Notification (if any). The User's Identity will be used if no FriendlyName has been set.
${USER_FRIENDLY_NAME} Will be replaced with the FriendlyName of the User who triggered the Push Notification (if any). The User's Identity will be used if no FriendlyName has been set.
${USER_IDENTITY} Will be replaced with the Identity of the User who triggered the Push Notification.
${USER_SID} Will be replaced with the Sid of the User who triggered the Push Notification (if any). The User's Identity will be used if no Sid is available.
${CHANNEL} Will be replaced with the UniqueName, FriendlyName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification.
${CHANNEL_FRIENDLY_NAME} Will be replaced with the FriendlyName, UniqueName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification.
${CHANNEL_SID} Will be replaced with the ChannelSid. This property is tied to the Channel related to the Push Notification.
${CHANNEL_UNIQUE_NAME} Will be replaced with the UniqueName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification.
${MESSAGE} Will be replaced with the body of the actual Message. Only used for notifications of type: New Message

注 : The maximum length of the entire notification payload is 110 characters. This substring is applied after the notification payload is constructed and the variables data applied. Thus, freeform text and the variable data are compiled into a string and the first 110 characters are then used as the notification payload.

Note: Variables can be used multiple times within a template, but each variable will contribute to the maximum number of available characters.

既定のテンプレート

プッシュ通知の種類 既定のテンプレート
New Message ${CHANNEL};${USER}: ${MESSAGE}
Added to Channel You have been added to channel ${CHANNEL} by ${USER}
Invited to Channel ${USER} has invited you to join the channel ${CHANNEL}
Removed from Channel ${USER} has removed you from the channel ${CHANNEL}

Configure Push Notifications

Each Push Notification type can be configured for a Service instance. The configuration allows each notification type to be enabled or disabled. This also handles custom template configuration as per the templating mechanism described above.

下記は有効な通知の type 名です:

  • NewMessage
  • AddedToChannel
  • InvitedToChannel
  • RemovedFromChannel

下記に使用される構成パラメーターを示します:

パラメーター名 description
Notifications.[type].Enabled true この種類のプッシュ通知が送信されるべき場合。 そうでない場合は false 既定値は false です。
Notifications.[type].Template 通知の種類向けのカスタム・テンプレート文字列です。
Notifications.[type].Sound The "sound" push payload parameter that will be set for this notification type.
Notifications.NewMessage.BadgeCountEnabled true if the NewMessage notification type should send a badge count value in the push payload. This parameter is only applicable to the NewMessage type. Please note that this is currently only used by the iOS APNS push notification type.

バッヂカウント

This setting is only for the NewMessage notification type. Currently, only APNS push notifications for iOS will use this and include the badge property in the payload. If enabled, the value of this property will represent the count of 1:1 Channels the User is a Member of which have any unread Messages for the User.

If Notifications.NewMessage.BadgeCountEnabled is set to true, decrements to the count of 1:1 Channels with unread messages will be sent to all registered iOS endpoints for that User.

        
        
        
        
        Configure the NewMessage Push Notification for a Service instance

        Configure NewMessage Push Notifications

        Configure the NewMessage Push Notification for a Service instance

        Setting additional notification types requires including them in your configuration request. For instance, to include the AddedToChannel Push Notification type, you can add

        'Notifications.AddedToChannel.Enabled=true' 
        'Notifications.AddedToChannel.Template=You are now a Member of ${CHANNEL}!  Added by ${USER}' 
        'Notifications.AddedToChannel.Sound=default'
        

        to your curl request.

        Next: Notifications on iOS

        Rate this page:

        ヘルプが必要ですか?

        誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。