Class: Twilio::REST::Notify::V1::ServiceContext::NotificationList

Inherits:
ListResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/notify/v1/service/notification.rb

Overview

PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid: nil) ⇒ NotificationList

Initialize the NotificationList

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String) (defaults to: nil)

    The service_sid



22
23
24
25
26
27
28
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 22

def initialize(version, service_sid: nil)
  super(version)

  # Path Solution
  @solution = {service_sid: service_sid}
  @uri = "/Services/#{@solution[:service_sid]}/Notifications"
end

Instance Method Details

#create(body: :unset, priority: :unset, ttl: :unset, title: :unset, sound: :unset, action: :unset, data: :unset, apn: :unset, gcm: :unset, sms: :unset, facebook_messenger: :unset, fcm: :unset, segment: :unset, alexa: :unset, to_binding: :unset, identity: :unset, tag: :unset) ⇒ NotificationInstance

Retrieve a single page of NotificationInstance records from the API. Request is executed immediately.

Parameters:

  • body (String) (defaults to: :unset)

    (optional for all except Alexa) Indicates the notification body text. Translates to ‘data.twi_body` for FCM and GCM, `aps.alert.body` for APNS, `Body` for SMS and Facebook Messenger and `request.message.data` for Alexa. For SMS either this, `body`, or the `media_url` attribute of the `Sms` parameter is required. For Facebook Messenger either this parameter or the body attribute in the `FacebookMessenger` parameter is required.

  • priority (notification.Priority) (defaults to: :unset)

    Two priorities defined: ‘low` and `high` (default). `low` optimizes the client app’s battery consumption, and notifications may be delivered with unspecified delay. This is the same as Normal priority for FCM and GCM or priority 5 for APNS. ‘high` sends the notification immediately, and can wake up a sleeping device. This is the same as High priority for FCM and GCM or priority 10 for APNS. This feature is not supported by SMS and Facebook Messenger and will be ignored for deliveries via those channels.

  • ttl (String) (defaults to: :unset)

    This parameter specifies how long (in seconds) the notification is valid. Delivery should be attempted if the device is offline. The maximum time to live supported is 4 weeks. The value zero means that the notification delivery is attempted immediately once but not stored for future delivery. The default value is 4 weeks. This feature is not supported by SMS and Facebook Messenger and will be ignored for deliveries via those channels.

  • title (String) (defaults to: :unset)

    (optional for all except Alexa) Indicates the notification title. This field is not visible on iOS phones and tablets but it is on Apple Watch and Android devices. Translates to ‘data.twi_title` for FCM and GCM, `aps.alert.title` for APNS and `displayInfo.content.title`, `displayInfo.content[].toast.primaryText` of `request.message` for Alexa. It is not supported for SMS and Facebook Messenger and will be omitted from deliveries via those channels.

  • sound (String) (defaults to: :unset)

    Indicates a sound to be played. Translates to ‘data.twi_sound` for FCM and GCM and `aps.sound` for APNS. This parameter is not supported by SMS and Facebook Messenger and is omitted from deliveries via those channels.

  • action (String) (defaults to: :unset)

    Specifies the actions to be displayed for the notification. Translates to ‘data.twi_action` for GCM and `aps.category` for APNS. This parameter is not supported by SMS and Facebook Messenger and is omitted from deliveries via those channels.

  • data (Hash) (defaults to: :unset)

    This parameter specifies the custom key-value pairs of the notification’s payload. Translates to ‘data` dictionary in FCM and GCM payload. FCM and GCM [reserves certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref) that cannot be used for those channels. For APNS, attributes of `Data` will be inserted into the APNS payload as custom properties outside of the `aps` dictionary. For Alexa they are added to `request.message.data`. For all channels, the `twi_` prefix is reserved for Twilio for future use. Requests including custom data with keys starting with `twi_` will be rejected as 400 Bad request and no delivery will be attempted. This parameter is not supported by SMS and Facebook Messenger and is omitted from deliveries via those channels.

  • apn (Hash) (defaults to: :unset)

    APNS specific payload that overrides corresponding attributes in a generic payload for Bindings with the apn BindingType. This value is mapped to the Payload item, therefore the ‘aps` key has to be used to change standard attributes. Adds custom key-value pairs to the root of the dictionary. Refer to [APNS documentation](developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) for more details. The `twi_` key prefix for custom key-value pairs is reserved for Twilio for future use. Custom data with keys starting with `twi_` is not allowed.

  • gcm (Hash) (defaults to: :unset)

    GCM specific payload that overrides corresponding attributes in generic payload for Bindings with gcm BindingType. This value is mapped to the root json dictionary. Refer to [GCM documentation](developers.google.com/cloud-messaging/http-server-ref) for more details. Target parameters ‘to`, `registration_ids`, and `notification_key` are not allowed. The `twi_` key prefix for custom key-value pairs is reserved for Twilio for future use. Custom data with keys starting with `twi_` is not allowed. FCM and GCM [reserves certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref) that cannot be used for those channels.

  • sms (Hash) (defaults to: :unset)

    SMS specific payload that overrides corresponding attributes in generic payload for Bindings with sms BindingType. Each attribute in this JSON object is mapped to the corresponding form parameter of the Twilio [Message](www.twilio.com/docs/api/rest/sending-messages) resource. The following parameters of the Message resource are supported in snake case format: ‘body`, `media_urls`, `status_callback`, and `max_price`. The `status_callback` parameter overrides the corresponding parameter in the messaging service if configured. The `media_urls` expects a JSON array.

  • facebook_messenger (Hash) (defaults to: :unset)

    Messenger specific payload that overrides corresponding attributes in generic payload for Bindings with facebook-messenger BindingType. This value is mapped to the root json dictionary of Facebook’s [Send API request](developers.facebook.com/docs/messenger-platform/send-api-reference). Overriding the ‘recipient` parameter is not allowed.

  • fcm (Hash) (defaults to: :unset)

    FCM specific payload that overrides corresponding attributes in generic payload for Bindings with fcm BindingType. This value is mapped to the root json dictionary. Refer to [FCM documentation](firebase.google.com/docs/cloud-messaging/http-server-ref#downstream) for more details. Target parameters ‘to`, `registration_ids`, `condition`, and `notification_key` are not allowed. The `twi_` key prefix for custom key-value pairs is reserved for Twilio for future use. Custom data with keys starting with `twi_` is not allowed. Custom data with keys starting with `twi_` is not allowed. FCM and GCM [reserves certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref) that cannot be used for those channels.

  • segment (String) (defaults to: :unset)

    The segment

  • alexa (Hash) (defaults to: :unset)

    The alexa

  • to_binding (String) (defaults to: :unset)

    The destination address in a JSON object (see attributes below). Multiple ToBinding parameters can be included but the total size of the request entity should not exceed 1MB. This is typically sufficient for 10,000 phone numbers.

  • identity (String) (defaults to: :unset)

    Delivery will be attempted only to Bindings with an Identity in this list. Maximum 20 items allowed in this list.

  • tag (String) (defaults to: :unset)

    Delivery will be attempted only to Bindings that have all of the Tags in this list. Maximum 5 items allowed in this list. The implicit tag “all” is available to notify all Bindings in a Service instance. Similarly the implicit tags “apn”, “fcm”, “gcm”, “sms” and “facebook-messenger” are available to notify all Bindings of the given type.

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 126

def create(body: :unset, priority: :unset, ttl: :unset, title: :unset, sound: :unset, action: :unset, data: :unset, apn: :unset, gcm: :unset, sms: :unset, facebook_messenger: :unset, fcm: :unset, segment: :unset, alexa: :unset, to_binding: :unset, identity: :unset, tag: :unset)
  data = Twilio::Values.of({
      'Identity' => Twilio.serialize_list(identity) { |e| e },
      'Tag' => Twilio.serialize_list(tag) { |e| e },
      'Body' => body,
      'Priority' => priority,
      'Ttl' => ttl,
      'Title' => title,
      'Sound' => sound,
      'Action' => action,
      'Data' => Twilio.serialize_object(data),
      'Apn' => Twilio.serialize_object(apn),
      'Gcm' => Twilio.serialize_object(gcm),
      'Sms' => Twilio.serialize_object(sms),
      'FacebookMessenger' => Twilio.serialize_object(facebook_messenger),
      'Fcm' => Twilio.serialize_object(fcm),
      'Segment' => Twilio.serialize_list(segment) { |e| e },
      'Alexa' => Twilio.serialize_object(alexa),
      'ToBinding' => Twilio.serialize_list(to_binding) { |e| e },
  })

  payload = @version.create(
      'POST',
      @uri,
      data: data
  )

  NotificationInstance.new(@version, payload, service_sid: @solution[:service_sid], )
end

#to_sObject

Provide a user friendly representation



158
159
160
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 158

def to_s
  '#<Twilio.Notify.V1.NotificationList>'
end