Class: Twi::Event

Inherits:
Resource show all
Defined in:
lib/twi/event.rb

Overview

The representation of an event tied to a (clasic) conversation.

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twi::Resource

Instance Method Details

#codeString?

Returns error code.

Returns:

  • (String, nil)

    error code



37
# File 'lib/twi/event.rb', line 37

def code = @params['ErrorCode']

#contentString?

Returns content.

Returns:

  • (String, nil)

    content



25
# File 'lib/twi/event.rb', line 25

def content = @params['Body']&.squish

#conversation_idString

Returns unique conversation identifier.

Returns:

  • (String)

    unique conversation identifier



34
# File 'lib/twi/event.rb', line 34

def conversation_id = @params['ConversationSid']

#idString

Returns unique message identifier.

Returns:

  • (String)

    unique message identifier



22
# File 'lib/twi/event.rb', line 22

def id = @params['MessageSid']

#image_urlsArray<String>

Returns URLs of image attachments.

Returns:

  • (Array<String>)

    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

#participantParticipant

Returns the participant the event is about (e.g.: joined the conversation).

Returns:

  • (Participant)

    the participant the event is about (e.g.: joined the conversation).



19
# File 'lib/twi/event.rb', line 19

def participant = Participant.new @params

#statusString

Returns conversation state, one of active, inactive, closed, initializing.

Returns:

  • (String)

    conversation state, one of active, inactive, closed, initializing.



16
# File 'lib/twi/event.rb', line 16

def status = @params['Status'] || @params['StateTo'] || @params['State']

#targetSymbol

Returns what the event is about.

Returns:

  • (Symbol)

    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