Class: Twi::Event
Overview
The representation of an event tied to a (clasic) conversation.
Instance Method Summary collapse
-
#code ⇒ String?
Error code.
-
#content ⇒ String?
Content.
-
#conversation_id ⇒ String
Unique conversation identifier.
-
#id ⇒ String
Unique message identifier.
-
#image_urls ⇒ Array<String>
URLs of image attachments.
-
#participant ⇒ Participant
The participant the event is about (e.g.: joined the conversation).
-
#status ⇒ String
Conversation state, one of active, inactive, closed, initializing.
-
#target ⇒ Symbol
What the event is about.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Twi::Resource
Instance Method Details
#code ⇒ String?
Returns error code.
37 |
# File 'lib/twi/event.rb', line 37 def code = @params['ErrorCode'] |
#content ⇒ String?
Returns content.
25 |
# File 'lib/twi/event.rb', line 25 def content = @params['Body']&.squish |
#conversation_id ⇒ String
Returns unique conversation identifier.
34 |
# File 'lib/twi/event.rb', line 34 def conversation_id = @params['ConversationSid'] |
#id ⇒ String
Returns unique message identifier.
22 |
# File 'lib/twi/event.rb', line 22 def id = @params['MessageSid'] |
#image_urls ⇒ Array<String>
Returns URLs of image attachments.
28 29 30 31 |
# File 'lib/twi/event.rb', line 28 def image_urls media = JSON(@params.fetch('Media', '[]')).map { |params| Medium.new params } media.filter(&:image?).map { |image| image.url } end |
#participant ⇒ Participant
Returns the participant the event is about (e.g.: joined the conversation).
19 |
# File 'lib/twi/event.rb', line 19 def participant = Participant.new @params |
#status ⇒ String
Returns conversation state, one of active, inactive, closed, initializing.
16 |
# File 'lib/twi/event.rb', line 16 def status = @params['Status'] || @params['StateTo'] || @params['State'] |
#target ⇒ Symbol
Returns what the event is about.
6 7 8 9 10 11 12 13 |
# File 'lib/twi/event.rb', line 6 def target case @params['EventType'] when 'onConversationAdded', 'onConversationStateUpdated' then :conversation when 'onParticipantAdded' then :participant when 'onMessageAdded' then :message when 'onDeliveryUpdated' then :delivery end end |