💎 ChatSDK Ruby

API: PostableMessage

ChatSDK::PostableMessage wraps outbound message content (text, cards, attachments, metadata) in a uniform structure.

ChatSDK::PostableMessage wraps outbound message content in a uniform structure that adapters can consume. It holds text, an optional card, attachments, and metadata.

Constructor

ChatSDK::PostableMessage.new(
  text: nil,
  card: nil,
  attachments: [],
  metadata: {}
)
ParameterTypeRequiredDefaultDescription
textStringNonilPlain text content
cardCards::NodeNonilRich card content
attachmentsArrayNo[]File or media attachments
metadataHashNo{}Arbitrary metadata passed to the adapter

Raises ArgumentError if both text and card are nil -- at least one is required.

Attributes

AttributeTypeDescription
textStringPlain text content
cardCards::NodeRich card node, or nil
attachmentsArrayAttachments array
metadataHashArbitrary metadata

Class Methods

PostableMessage.from(content)

Factory method that coerces various types into a PostableMessage.

PostableMessage.from("Hello")
# => PostableMessage(text: "Hello")

PostableMessage.from(ChatSDK.card(title: "Hi") { text "Body" })
# => PostableMessage(card: <Node>, text: "Hi\nBody")

PostableMessage.from(existing_postable_message)
# => existing_postable_message (returned as-is)
Input typeBehavior
PostableMessageReturned as-is (identity)
StringWrapped as PostableMessage.new(text: content)
Cards::NodeWrapped as PostableMessage.new(card: content, text: content.fallback_text)
Anything elseRaises ArgumentError

Instance Methods

card?

Returns true if the message contains a card.

msg = PostableMessage.new(text: "plain")
msg.card?  # => false

msg = PostableMessage.new(card: some_node, text: "fallback")
msg.card?  # => true

On this page