Class: Sendly::RcsMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/rcs_resource.rb

Overview

A message sent through the RCS channel. channel is "rcs" when it was delivered as RCS, or "sms" when the recipient couldn't receive RCS and the message fell back to plain SMS — check with #fell_back?. On a fallback fell_back_to is "sms" and +segments+/+credits_used+ are billed as SMS; rcs carries the channel-specific details either way.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ RcsMessage

Returns a new instance of RcsMessage.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/sendly/rcs_resource.rb', line 100

def initialize(data)
  @id = data["id"]
  @channel = data["channel"] || "rcs"
  @fell_back_to = data["fellBackTo"] || data["fell_back_to"]
  @message_format = data["message_format"] || data["messageFormat"] || @channel
  @to = data["to"]
  @from = data["from"]
  @text = data["text"]
  @status = data["status"]
  @segments = data["segments"] || 1
  @credits_used = data["creditsUsed"] || data["credits_used"] || 0
  @rcs = data["rcs"] ? RcsMessageDetails.new(data["rcs"]) : nil
  @created_at = data["createdAt"] || data["created_at"]
  @metadata = data["metadata"]
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def channel
  @channel
end

#created_atObject (readonly)

Returns the value of attribute created_at.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def created_at
  @created_at
end

#credits_usedObject (readonly)

Returns the value of attribute credits_used.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def credits_used
  @credits_used
end

#fell_back_toObject (readonly)

Returns the value of attribute fell_back_to.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def fell_back_to
  @fell_back_to
end

#fromObject (readonly)

Returns the value of attribute from.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def from
  @from
end

#idObject (readonly)

Returns the value of attribute id.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def id
  @id
end

#message_formatObject (readonly)

Returns the value of attribute message_format.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def message_format
  @message_format
end

#metadataObject (readonly)

Returns the value of attribute metadata.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def 
  @metadata
end

#rcsObject (readonly)

Returns the value of attribute rcs.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def rcs
  @rcs
end

#segmentsObject (readonly)

Returns the value of attribute segments.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def segments
  @segments
end

#statusObject (readonly)

Returns the value of attribute status.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def text
  @text
end

#toObject (readonly)

Returns the value of attribute to.



96
97
98
# File 'lib/sendly/rcs_resource.rb', line 96

def to
  @to
end

Instance Method Details

#delivered?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/sendly/rcs_resource.rb', line 120

def delivered?
  status == "delivered"
end

#failed?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/sendly/rcs_resource.rb', line 124

def failed?
  status == "failed"
end

#fell_back?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/sendly/rcs_resource.rb', line 116

def fell_back?
  fell_back_to == "sms"
end

#to_hObject



128
129
130
131
132
133
134
135
# File 'lib/sendly/rcs_resource.rb', line 128

def to_h
  {
    id: id, channel: channel, fell_back_to: fell_back_to,
    message_format: message_format, to: to, from: from, text: text,
    status: status, segments: segments, credits_used: credits_used,
    rcs: rcs&.to_h, created_at: created_at, metadata: 
  }.compact
end