Class: ChatSDK::PostableMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/chat_sdk/postable_message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, card: nil, attachments: [], metadata: {}) ⇒ PostableMessage

Returns a new instance of PostableMessage.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/chat_sdk/postable_message.rb', line 7

def initialize(text: nil, card: nil, attachments: [], metadata: {})
  raise ArgumentError, "text or card required" if text.nil? && card.nil?
  @text = text
  @card = card
  @attachments = attachments
  @metadata = 
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



5
6
7
# File 'lib/chat_sdk/postable_message.rb', line 5

def attachments
  @attachments
end

#cardObject (readonly)

Returns the value of attribute card.



5
6
7
# File 'lib/chat_sdk/postable_message.rb', line 5

def card
  @card
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/chat_sdk/postable_message.rb', line 5

def 
  @metadata
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/chat_sdk/postable_message.rb', line 5

def text
  @text
end

Class Method Details

.from(content) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/chat_sdk/postable_message.rb', line 19

def self.from(content)
  case content
  when PostableMessage then content
  when String then new(text: content)
  when Cards::Node then new(card: content, text: content.fallback_text)
  else raise ArgumentError, "cannot convert #{content.class} to PostableMessage"
  end
end

Instance Method Details

#card?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/chat_sdk/postable_message.rb', line 15

def card?
  !@card.nil?
end