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.



260
261
262
263
264
265
266
267
268
269
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 260

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



273
274
275
276
277
278
279
280
281
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 273

def delete

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    

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

#delete_with_metadataBoolean

Delete the WebhookInstanceMetadata

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 286

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
      response = @version.('DELETE', @uri, headers: headers)
      webhook_instance = WebhookInstance.new(
          @version,
          response.body,
          account_sid: @solution[:account_sid],
          sid: @solution[:sid],
      )
      .new(@version, webhook_instance, response.headers, response.status_code)
end

#fetchWebhookInstance

Fetch the WebhookInstance

Returns:



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 305

def fetch

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    payload = @version.fetch('GET', @uri, headers: headers)
    WebhookInstance.new(
        @version,
        payload,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
end

#fetch_with_metadataWebhookInstance

Fetch the WebhookInstanceMetadata

Returns:



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 326

def 

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('GET', @uri, headers: headers)
    webhook_instance = WebhookInstance.new(
        @version,
        response.body,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        webhook_instance,
        response.headers,
        response.status_code
    )
end

#inspectObject

Provide a detailed, user friendly representation



452
453
454
455
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 452

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

#to_sObject

Provide a user friendly representation



445
446
447
448
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 445

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:



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 359

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,
    })

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

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

Update the WebhookInstanceMetadata

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:



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 402

def (
  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,
    })

    headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
    
    
    
    
    
    response = @version.('POST', @uri, data: data, headers: headers)
    webhook_instance = WebhookInstance.new(
        @version,
        response.body,
        service_sid: @solution[:service_sid],
        channel_sid: @solution[:channel_sid],
        sid: @solution[:sid],
    )
    .new(
        @version,
        webhook_instance,
        response.headers,
        response.status_code
    )
end