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

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

Instance Method Summary collapse

Constructor Details

#initialize(version, payload, service_sid: nil, channel_sid: nil, sid: nil) ⇒ WebhookInstance

Initialize the WebhookInstance

Parameters:

  • version (Version)

    Version that contains the resource

  • payload (Hash)

    payload that contains response from Twilio

  • account_sid (String)

    The SID of the Account that created this Webhook resource.

  • sid (String) (defaults to: nil)

    The SID of the Call resource to fetch.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 612

def initialize(version, payload , service_sid: nil, channel_sid: nil, sid: nil)
    super(version)
    
    
    # Marshaled Properties
    @properties = { 
        'sid' => payload['sid'],
        'account_sid' => payload['account_sid'],
        'service_sid' => payload['service_sid'],
        'channel_sid' => payload['channel_sid'],
        'type' => payload['type'],
        'url' => payload['url'],
        'configuration' => payload['configuration'],
        'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
        'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
    }

    # Context
    @instance_context = nil
    @params = { 'service_sid' => service_sid  || @properties['service_sid']  ,'channel_sid' => channel_sid  || @properties['channel_sid']  ,'sid' => sid  || @properties['sid']  , }
end

Instance Method Details

#account_sidString

Returns The SID of the Account that created the Channel Webhook resource.

Returns:

  • (String)

    The SID of the Account that created the Channel Webhook resource.



653
654
655
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 653

def 
    @properties['account_sid']
end

#channel_sidString

Returns The SID of the Channel the Channel Webhook resource belongs to.

Returns:

  • (String)

    The SID of the Channel the Channel Webhook resource belongs to.



665
666
667
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 665

def channel_sid
    @properties['channel_sid']
end

#configurationHash

Returns The JSON string that describes how the channel webhook is configured. The configuration object contains the url, method, filters, and retry_count values that are configured by the create and update actions.

Returns:

  • (Hash)

    The JSON string that describes how the channel webhook is configured. The configuration object contains the url, method, filters, and retry_count values that are configured by the create and update actions.



683
684
685
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 683

def configuration
    @properties['configuration']
end

#contextWebhookContext

Generate an instance context for the instance, the context is capable of performing various actions. All instance actions are proxied to the context

Returns:



638
639
640
641
642
643
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 638

def context
    unless @instance_context
        @instance_context = WebhookContext.new(@version , @params['service_sid'], @params['channel_sid'], @params['sid'])
    end
    @instance_context
end

#date_createdTime

Returns The date and time in GMT when the resource was created specified in ISO 8601 format.

Returns:

  • (Time)

    The date and time in GMT when the resource was created specified in ISO 8601 format.



689
690
691
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 689

def date_created
    @properties['date_created']
end

#date_updatedTime

Returns The date and time in GMT when the resource was last updated specified in ISO 8601 format.

Returns:

  • (Time)

    The date and time in GMT when the resource was last updated specified in ISO 8601 format.



695
696
697
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 695

def date_updated
    @properties['date_updated']
end

#deleteBoolean

Delete the WebhookInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



702
703
704
705
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 702

def delete

    context.delete
end

#fetchWebhookInstance

Fetch the WebhookInstance

Returns:



710
711
712
713
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 710

def fetch

    context.fetch
end

#inspectObject

Provide a detailed, user friendly representation



752
753
754
755
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 752

def inspect
    values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Chat.V2.WebhookInstance #{values}>"
end

#service_sidString

Returns The SID of the Service the Channel Webhook resource is associated with.

Returns:

  • (String)

    The SID of the Service the Channel Webhook resource is associated with.



659
660
661
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 659

def service_sid
    @properties['service_sid']
end

#sidString

Returns The unique string that we created to identify the Channel Webhook resource.

Returns:

  • (String)

    The unique string that we created to identify the Channel Webhook resource.



647
648
649
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 647

def sid
    @properties['sid']
end

#to_sObject

Provide a user friendly representation



745
746
747
748
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 745

def to_s
    values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Chat.V2.WebhookInstance #{values}>"
end

#typeString

Returns The type of webhook. Can be: webhook, studio, or trigger.

Returns:

  • (String)

    The type of webhook. Can be: webhook, studio, or trigger.



671
672
673
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 671

def type
    @properties['type']
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.

  • 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 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:



724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 724

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

    context.update(
        configuration_url: configuration_url, 
        configuration_method: configuration_method, 
        configuration_filters: configuration_filters, 
        configuration_triggers: configuration_triggers, 
        configuration_flow_sid: configuration_flow_sid, 
        configuration_retry_count: configuration_retry_count, 
    )
end

#urlString

Returns The absolute URL of the Channel Webhook resource.

Returns:

  • (String)

    The absolute URL of the Channel Webhook resource.



677
678
679
# File 'lib/twilio-ruby/rest/chat/v2/service/channel/webhook.rb', line 677

def url
    @properties['url']
end