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

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

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid: nil) ⇒ NotificationList

Initialize the NotificationList

Parameters:

  • version (Version)

    Version that contains the resource



28
29
30
31
32
33
34
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 28

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, delivery_callback_url: :unset, identity: :unset, tag: :unset) ⇒ NotificationInstance

Create the NotificationInstance

Parameters:

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

    The notification text. For FCM and GCM, translates to data.twi_body. For APNS, translates to aps.alert.body. For SMS, translates to body. SMS requires either this body value, or media_urls attribute defined in the sms parameter of the notification.

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

    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 (String) (defaults to: :unset)

    The notification title. For FCM and GCM, this translates to the data.twi_title value. For APNS, this translates to the aps.alert.title value. SMS does not support this property. This field is not visible on iOS phones and tablets but appears on Apple Watch and Android devices.

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

    The name of the sound to be played for the notification. For FCM and GCM, this Translates to data.twi_sound. For APNS, this translates to aps.sound. SMS does not support this property.

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

    The actions to display for the notification. For APNS, translates to the aps.category value. For GCM, translates to the data.twi_action value. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

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

    The custom key-value pairs of the notification’s payload. For FCM and GCM, this value translates to data in the FCM and GCM payloads. FCM and GCM [reserve certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref) that cannot be used in those channels. For APNS, attributes of data are inserted into the APNS payload as custom properties outside of the aps dictionary. In all channels, we reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed and are rejected as 400 Bad request with no delivery attempted. For SMS, this parameter is not supported and is omitted from deliveries to those channels.

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

    The APNS-specific payload that overrides corresponding attributes in the generic payload for APNS Bindings. This property maps to the APNS Payload item, therefore the aps key must be used to change standard attributes. Adds custom key-value pairs to the root of the dictionary. See the [APNS documentation](developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) for more details. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed.

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

    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](firebase.google.com/docs/cloud-messaging/http-server-ref) for more details. Target parameters to, registration_ids, and notification_key are not allowed. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed. GCM also [reserves certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref).

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

    The SMS-specific payload that overrides corresponding attributes in the generic payload for SMS Bindings. Each attribute in this value maps to the corresponding form parameter of the Twilio [Message](www.twilio.com/docs/sms/quickstart) resource. These 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 property expects a JSON array.

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

    Deprecated.

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

    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](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 in this parameter. We reserve keys that start with twi_ for future use. Custom keys that start with twi_ are not allowed. FCM also [reserves certain keys](firebase.google.com/docs/cloud-messaging/http-server-ref), which cannot be used in that channel.

  • segment (Array[String]) (defaults to: :unset)

    The Segment resource is deprecated. Use the tag parameter, instead.

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

    Deprecated.

  • to_binding (Array[String]) (defaults to: :unset)

    The destination address specified as a JSON string. Multiple to_binding 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.

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

    URL to send webhooks.

  • identity (Array[String]) (defaults to: :unset)

    The identity value that uniquely identifies the new resource’s [User](www.twilio.com/docs/chat/rest/user-resource) within the [Service](www.twilio.com/docs/notify/api/service-resource). Delivery will be attempted only to Bindings with an Identity in this list. No more than 20 items are allowed in this list.

  • tag (Array[String]) (defaults to: :unset)

    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 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 in a specific channel.

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 56

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, 
    delivery_callback_url: :unset, 
    identity: :unset, 
    tag: :unset
)

    data = Twilio::Values.of({
        '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 },
        'DeliveryCallbackUrl' => delivery_callback_url,
        'Identity' => Twilio.serialize_list(identity) { |e| e },
        'Tag' => Twilio.serialize_list(tag) { |e| e },
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.create('POST', @uri, data: data, headers: headers)
    NotificationInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
    )
end

#to_sObject

Provide a user friendly representation



116
117
118
# File 'lib/twilio-ruby/rest/notify/v1/service/notification.rb', line 116

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