メニュー

Expand
ページを評価:

プッシュ通知の構成

Using push notifications with your Conversations implementation drives your customers to re-engage with your app. With Twilio Conversations, you can configure pushes for: * New Messages * New Media Messages (new! since October, 2021) * Conversations you've joined * Conversations you've left

Conversations integrates APN (iOS) and FCM (Android and browsers) using the Push credentials configured on your Twilio account. The content and payload of your push notifications will be different depending on the event that precipitates them.

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

  • Selecting which of the eligible Conversations events should trigger push notifications
  • 各メッセージタイプごとのペイロード・テンプレートの記述(既定のテンプレートの上書き)

目次

プッシュ通知の種類

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

プッシュ通知の種類 概要
New Message This is sent to each chat participant in a Conversation whenever a new Message is posted.
New Media Message This is sent to each chat participant in a Conversation whenever a new message is posted with Media (instead of text).
Added to Conversation This is sent to chat participants that have been added to a Conversation
Removed from Conversation This is sent to chat participants that have been removed from a Conversation

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.

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

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:

テンプレート変数

テンプレート変数 概要
${PARTICIPANT} Will be replaced with the FriendlyName of the Participant's underlying User who triggered the Push Notification (if any). The User's Identity will be used if no FriendlyName has been set.
For Proxy Participants engaged via a non-chat channel, the MessagingBinding.Address will be used instead.
When group texting, the MessagingBinding.Address will be used, or the MessagingBinding.ProjectedAddress if the Participant uses a Twilio phone number and has no underlying User.
${PARTICIPANT_FRIENDLY_NAME} Synonym of ${PARTICIPANT}.
${PARTICIPANT_IDENTITY} Synonym of ${PARTICIPANT}.
${PARTICIPANT_SID} Will be replaced with the Sid of the Participant who triggered the Push Notification (if any). The Participant's Identity will be used if no Sid is available.
${CONVERSATION} Will be replaced with the UniqueName, FriendlyName or ConversationSid (if they exist, in that order of priority). These properties are tied to the Conversation related to the Push Notification.
${CONVERSATION_FRIENDLY_NAME} Will be replaced with the FriendlyName, UniqueName or ConversationSid (if they exist, in that order of priority). These properties are tied to the Conversation related to the Push Notification.
${CONVERSATION_SID} Will be replaced with the ConversationSid. This property is tied to the Conversation related to the Push Notification.
${CONVERSATION_UNIQUE_NAME} Will be replaced with the UniqueName, or the FriendlyName, or ConversationSid (in that order) of the conversation to which this push pertains.
${MESSAGE} Will be replaced with the body of the actual Message. Only used for notifications of type: New Message
${MEDIA_COUNT} Sent exclusively for New Media Message pushes, counts the number of media files included. Presently, this will never be higher than 1; support for multiple media on the same message is coming soon.
${MEDIA} Sent exclusively for New Media Message pushes, presents the filename of the first media attached to the 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 ${CONVERSATION}:${PARTICIPANT}: ${MESSAGE}
New Media Message You have a new message in ${CONVERSATION} with ${MEDIA_COUNT} media files: ${MEDIA}
Added to Conversation You have been added to the conversation ${CONVERSATION} by ${PARTICIPANT}
Removed from Conversation ${PARTICIPANT} has removed you from the conversation ${CONVERSATION}

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
  • AddedToConversation
  • RemovedFromConversation

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

パラメーター名 description
[type].Enabled Set true to send this type of push notification. Default: false
[type].Template 通知の種類向けのカスタム・テンプレート文字列です。
[type].Sound The "sound" push payload parameter that will be set for this notification type, appropriately to the target platfrom.
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.
NewMessage.WithMedia.Enabled Set true to send pushes for media messages. Default: false.
NewMessage.WithMedia.Template A specific template for new media message pushes, different and independent of NewMessage.Template.

バッヂカウント

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 Conversations the User participates in which have any unread Messages for the User.

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

        
        
        
              
              
              
              In early versions of Conversations, media messages didn't trigger push notifications. Enable them now with this incantation.

              Enable Media Pushes

              In early versions of Conversations, media messages didn't trigger push notifications. Enable them now with this incantation.

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

              'AddedToConversation.Enabled=true' 
              'AddedToConversation.Template=You are now a participant of ${CONVERSATION}!  Added by ${PARTICIPANT}' 
              'AddedToConversation.Sound=default'
              
              ページを評価:

              ヘルプが必要ですか?

              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 Community Forums or browsing the Twilio tag on Stack Overflow.

                    
                    
                    

                    フィードバックくださりありがとうございます!

                    We are always striving to improve our documentation quality, and your feedback is valuable to us. Please select the reason(s) for your feedback or provide additional information about how we can improve:

                    Sending your feedback...
                    🎉 Thank you for your feedback!
                    Something went wrong. Please try again.

                    Thanks for your feedback!

                    Refer us and get $10 in 3 simple steps!

                    ステップ1

                    Get link

                    Get a free personal referral link here

                    ステップ2:

                    Give $10

                    Your user signs up and upgrade using link

                    ステップ3

                    Get $10

                    1,250 free SMSes
                    OR 1,000 free voice mins
                    OR 12,000 chats
                    OR more