Class: Twi::MessageEvent

Inherits:
Event show all
Defined in:
lib/twi/message_event.rb

Overview

An event signaling a new message in a conversation.

Class Method Summary collapse

Methods inherited from Event

#code, #content, #conversation_id, #id, #image_urls, #participant, participant_params_for, #status, #target

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twi::Resource

Class Method Details

.media_params_for(media) ⇒ Object



15
16
17
18
19
# File 'lib/twi/message_event.rb', line 15

def self.media_params_for(media)
  media.map do |medium|
    { Sid: medium[:id], ContentType: medium[:content_type] }
  end.to_json if media.present?
end

.params_for(id:, participant_id:, content: nil, media: []) ⇒ Hash

Returns the shape of the payload send by Twilio to the callback URL.

Returns:

  • (Hash)

    the shape of the payload send by Twilio to the callback URL.



6
7
8
9
10
11
# File 'lib/twi/message_event.rb', line 6

def self.params_for(id:, participant_id:, content: nil, media: [])
  {
    ConversationSid: id, EventType: 'onMessageChanged', ParticipantSid: participant_id.to_s,
    MessageSid: "SM#{rand}", Body: content, Media: media_params_for(media),
  }.compact_blank
end