Class: Twilio::REST::Chat::V2::ServiceContext::ChannelContext::WebhookContext

Inherits:
InstanceContext
  • Object
show all
Defined in:
lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, service_sid, channel_sid, sid) ⇒ WebhookContext

Initialize the WebhookContext

Parameters:

  • version (Version)

    Version that contains the resource

  • service_sid (String)

    The SID of the [Service](www.twilio.com/docs/chat/rest/service-resource) with the Channel that has the Webhook resource to update.

  • channel_sid (String)

    The SID of the [Channel](www.twilio.com/docs/chat/channels) the Channel Webhook resource to update belongs to. This value can be the Channel resource’s ‘sid` or `unique_name`.

  • sid (String)

    The SID of the Channel Webhook resource to update.



177
178
179
180
181
182
183
184
185
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 177

def initialize(version, service_sid, channel_sid, sid)
    super(version)

    # Path Solution
    @solution = { service_sid: service_sid, channel_sid: channel_sid, sid: sid,  }
    @uri = "/Services/#{@solution[:service_sid]}/Channels/#{@solution[:channel_sid]}/Webhooks/#{@solution[:sid]}"

    
end

Instance Method Details

#deleteBoolean

Delete the WebhookInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



189
190
191
192
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 189

def delete

    @version.delete('DELETE', @uri)
end

#fetchWebhookInstance

Fetch the WebhookInstance

Returns:



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 197

def fetch

    payload = @version.fetch('GET', @uri)
    WebhookInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
end

#inspectObject

Provide a detailed, user friendly representation



256
257
258
259
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 256

def inspect
    context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
    "#<Twilio.Chat.V2.WebhookContext #{context}>"
end

#to_sObject

Provide a user friendly representation



249
250
251
252
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 249

def to_s
    context = @solution.map{|k, v| "#{k}: #{v}"}.join(',')
    "#<Twilio.Chat.V2.WebhookContext #{context}>"
end

#update(configuration_url: :unset, configuration_method: :unset, configuration_filters: :unset, configuration_triggers: :unset, configuration_flow_sid: :unset, configuration_retry_count: :unset) ⇒ WebhookInstance

Update the WebhookInstance

Parameters:

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

    The URL of the webhook to call using the ‘configuration.method`.

  • configuration_method (Method) (defaults to: :unset)
  • configuration_filters (Array[String]) (defaults to: :unset)

    The events that cause us to call the Channel Webhook. Used when ‘type` is `webhook`. This parameter takes only one event. To specify more than one event, repeat this parameter for each event. For the list of possible events, see [Webhook Event Triggers](www.twilio.com/docs/chat/webhook-events#webhook-event-trigger).

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

    A string that will cause us to call the webhook when it is present in a message body. This parameter takes only one trigger string. To specify more than one, repeat this parameter for each trigger string up to a total of 5 trigger strings. Used only when ‘type` = `trigger`.

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

    The SID of the Studio [Flow](www.twilio.com/docs/studio/rest-api/flow) to call when an event in ‘configuration.filters` occurs. Used only when `type` = `studio`.

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

    The number of times to retry the webhook if the first attempt fails. Can be an integer between 0 and 3, inclusive, and the default is 0.

Returns:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 218

def update(
    configuration_url: :unset, 
    configuration_method: :unset, 
    configuration_filters: :unset, 
    configuration_triggers: :unset, 
    configuration_flow_sid: :unset, 
    configuration_retry_count: :unset
)

    data = Twilio::Values.of({
        'Configuration.Url' => configuration_url,
        'Configuration.Method' => configuration_method,
        'Configuration.Filters' => Twilio.serialize_list(configuration_filters) { |e| e },
        'Configuration.Triggers' => Twilio.serialize_list(configuration_triggers) { |e| e },
        'Configuration.FlowSid' => configuration_flow_sid,
        'Configuration.RetryCount' => configuration_retry_count,
    })

    payload = @version.update('POST', @uri, data: data)
    WebhookInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
end