Class: Talkbird::Entity::Message
- Inherits:
-
Object
- Object
- Talkbird::Entity::Message
- Defined in:
- lib/talkbird/entity/message.rb
Overview
SendBird message
Constant Summary collapse
- DEFAULTS =
{ type: 'MESG' }.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(from, to, body, options = {}) ⇒ Message
constructor
A new instance of Message.
- #options ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(from, to, body, options = {}) ⇒ Message
Returns a new instance of Message.
24 25 26 27 28 29 30 |
# File 'lib/talkbird/entity/message.rb', line 24 def initialize(from, to, body, = {}) @sender = User.find_or_create(from) @receiver = User.find_or_create(to) @body = body @options = end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/talkbird/entity/message.rb', line 10 def body @body end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
9 10 11 |
# File 'lib/talkbird/entity/message.rb', line 9 def receiver @receiver end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender.
8 9 10 |
# File 'lib/talkbird/entity/message.rb', line 8 def sender @sender end |
Class Method Details
.build(response) ⇒ Object
18 19 20 |
# File 'lib/talkbird/entity/message.rb', line 18 def build(response) response end |
Instance Method Details
#deliver ⇒ Object
32 33 34 35 36 37 |
# File 'lib/talkbird/entity/message.rb', line 32 def deliver return false if !sender || !receiver channel = Entity::Channel.find_or_create(sender.id, receiver.id) channel.update(self) end |
#options ⇒ Object
46 47 48 |
# File 'lib/talkbird/entity/message.rb', line 46 def DEFAULTS.merge(@options) end |
#to_h ⇒ Object
39 40 41 42 43 44 |
# File 'lib/talkbird/entity/message.rb', line 39 def to_h .merge( user_id: sender.id, message: body ) end |