Class: Repull::Message

Inherits:
ApiModelBase show all
Defined in:
lib/repull/models/message.rb

Overview

A single message inside a conversation thread. Returned by ‘GET /v1/conversations/#id/messages`. `direction` is normalized to `inbound` (from the guest) / `outbound` (from the host or an automation).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ Message

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/repull/models/message.rb', line 122

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Repull::Message` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Repull::Message`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'external_message_id')
    self.external_message_id = attributes[:'external_message_id']
  end

  if attributes.key?(:'direction')
    self.direction = attributes[:'direction']
  end

  if attributes.key?(:'sender_type')
    self.sender_type = attributes[:'sender_type']
  end

  if attributes.key?(:'sender_name')
    self.sender_name = attributes[:'sender_name']
  end

  if attributes.key?(:'sender_avatar')
    self.sender_avatar = attributes[:'sender_avatar']
  end

  if attributes.key?(:'channel')
    self.channel = attributes[:'channel']
  end

  if attributes.key?(:'body')
    self.body = attributes[:'body']
  end

  if attributes.key?(:'translated_body')
    self.translated_body = attributes[:'translated_body']
  end

  if attributes.key?(:'attachments')
    if (value = attributes[:'attachments']).is_a?(Array)
      self.attachments = value
    end
  end

  if attributes.key?(:'is_automated')
    self.is_automated = attributes[:'is_automated']
  end

  if attributes.key?(:'ai_generated')
    self.ai_generated = attributes[:'ai_generated']
  end

  if attributes.key?(:'sent_at')
    self.sent_at = attributes[:'sent_at']
  end

  if attributes.key?(:'delivered_at')
    self.delivered_at = attributes[:'delivered_at']
  end

  if attributes.key?(:'read_at')
    self.read_at = attributes[:'read_at']
  end
end

Instance Attribute Details

#ai_generatedObject

‘true` when the body was authored by Vanio AI (autopilot, draft).



48
49
50
# File 'lib/repull/models/message.rb', line 48

def ai_generated
  @ai_generated
end

#attachmentsObject

Returns the value of attribute attachments.



42
43
44
# File 'lib/repull/models/message.rb', line 42

def attachments
  @attachments
end

#bodyObject

Message body in the original language.



37
38
39
# File 'lib/repull/models/message.rb', line 37

def body
  @body
end

#channelObject

Delivery channel — ‘airbnb`, `booking`, `sms`, `email`, etc.



34
35
36
# File 'lib/repull/models/message.rb', line 34

def channel
  @channel
end

#delivered_atObject

Returns the value of attribute delivered_at.



52
53
54
# File 'lib/repull/models/message.rb', line 52

def delivered_at
  @delivered_at
end

#directionObject

Returns the value of attribute direction.



24
25
26
# File 'lib/repull/models/message.rb', line 24

def direction
  @direction
end

#external_message_idObject

ID assigned by the source channel (Airbnb message id, Booking message id, etc.). Stable across syncs.



22
23
24
# File 'lib/repull/models/message.rb', line 22

def external_message_id
  @external_message_id
end

#idObject

Returns the value of attribute id.



19
20
21
# File 'lib/repull/models/message.rb', line 19

def id
  @id
end

#is_automatedObject

‘true` when the message was sent by a Vanio automation (template, schedule, etc.).



45
46
47
# File 'lib/repull/models/message.rb', line 45

def is_automated
  @is_automated
end

#read_atObject

Returns the value of attribute read_at.



54
55
56
# File 'lib/repull/models/message.rb', line 54

def read_at
  @read_at
end

#sender_avatarObject

Returns the value of attribute sender_avatar.



31
32
33
# File 'lib/repull/models/message.rb', line 31

def sender_avatar
  @sender_avatar
end

#sender_nameObject

Returns the value of attribute sender_name.



29
30
31
# File 'lib/repull/models/message.rb', line 29

def sender_name
  @sender_name
end

#sender_typeObject

Free-form sender role from the channel (e.g. ‘guest`, `host`, `system`, `airbnb`). Use `direction` for binary inbound/outbound logic.



27
28
29
# File 'lib/repull/models/message.rb', line 27

def sender_type
  @sender_type
end

#sent_atObject

Returns the value of attribute sent_at.



50
51
52
# File 'lib/repull/models/message.rb', line 50

def sent_at
  @sent_at
end

#translated_bodyObject

English translation when the original language is non-English and a translation has been computed.



40
41
42
# File 'lib/repull/models/message.rb', line 40

def translated_body
  @translated_body
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



78
79
80
# File 'lib/repull/models/message.rb', line 78

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



83
84
85
# File 'lib/repull/models/message.rb', line 83

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/repull/models/message.rb', line 57

def self.attribute_map
  {
    :'id' => :'id',
    :'external_message_id' => :'externalMessageId',
    :'direction' => :'direction',
    :'sender_type' => :'senderType',
    :'sender_name' => :'senderName',
    :'sender_avatar' => :'senderAvatar',
    :'channel' => :'channel',
    :'body' => :'body',
    :'translated_body' => :'translatedBody',
    :'attachments' => :'attachments',
    :'is_automated' => :'isAutomated',
    :'ai_generated' => :'aiGenerated',
    :'sent_at' => :'sentAt',
    :'delivered_at' => :'deliveredAt',
    :'read_at' => :'readAt'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/repull/models/message.rb', line 251

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



109
110
111
112
113
114
115
116
117
118
# File 'lib/repull/models/message.rb', line 109

def self.openapi_nullable
  Set.new([
    :'external_message_id',
    :'sender_type',
    :'sender_avatar',
    :'channel',
    :'translated_body',
    :'read_at'
  ])
end

.openapi_typesObject

Attribute type mapping.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/repull/models/message.rb', line 88

def self.openapi_types
  {
    :'id' => :'String',
    :'external_message_id' => :'String',
    :'direction' => :'String',
    :'sender_type' => :'String',
    :'sender_name' => :'String',
    :'sender_avatar' => :'String',
    :'channel' => :'String',
    :'body' => :'String',
    :'translated_body' => :'String',
    :'attachments' => :'Array<ConversationMessageAttachment>',
    :'is_automated' => :'Boolean',
    :'ai_generated' => :'Boolean',
    :'sent_at' => :'Time',
    :'delivered_at' => :'Time',
    :'read_at' => :'Time'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/repull/models/message.rb', line 216

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      external_message_id == o.external_message_id &&
      direction == o.direction &&
      sender_type == o.sender_type &&
      sender_name == o.sender_name &&
      sender_avatar == o.sender_avatar &&
      channel == o.channel &&
      body == o.body &&
      translated_body == o.translated_body &&
      attachments == o.attachments &&
      is_automated == o.is_automated &&
      ai_generated == o.ai_generated &&
      sent_at == o.sent_at &&
      delivered_at == o.delivered_at &&
      read_at == o.read_at
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


238
239
240
# File 'lib/repull/models/message.rb', line 238

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



244
245
246
# File 'lib/repull/models/message.rb', line 244

def hash
  [id, external_message_id, direction, sender_type, sender_name, sender_avatar, channel, body, translated_body, attachments, is_automated, ai_generated, sent_at, delivered_at, read_at].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



201
202
203
204
205
# File 'lib/repull/models/message.rb', line 201

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/repull/models/message.rb', line 273

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



209
210
211
212
# File 'lib/repull/models/message.rb', line 209

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  true
end