Class: Telerivet::Message

Inherits:
Entity
  • Object
show all
Defined in:
lib/telerivet/message.rb

Overview

Represents a single message.

Fields:

- id (string, max 34 characters)
    * ID of the message
    * Read-only

- direction
    * Direction of the message: incoming messages are sent from one of your contacts to
        your phone; outgoing messages are sent from your phone to one of your contacts
    * Allowed values: incoming, outgoing
    * Read-only

- status
    * Current status of the message
    * Allowed values: ignored, processing, received, sent, queued, failed, failed_queued,
        cancelled, delivered, not_delivered
    * Read-only

- message_type
    * Type of the message
    * Allowed values: sms, mms, ussd, call
    * Read-only

- source
    * How the message originated within Telerivet
    * Allowed values: phone, provider, web, api, service, webhook, scheduled
    * Read-only

- time_created (UNIX timestamp)
    * The time that the message was created on Telerivet's servers
    * Read-only

- time_sent (UNIX timestamp)
    * The time that the message was reported to have been sent (null for incoming messages
        and messages that have not yet been sent)
    * Read-only

- from_number (string)
    * The phone number that the message originated from (your number for outgoing
        messages, the contact's number for incoming messages)
    * Read-only

- to_number (string)
    * The phone number that the message was sent to (your number for incoming messages,
        the contact's number for outgoing messages)
    * Read-only

- content (string)
    * The text content of the message (null for USSD messages and calls)
    * Read-only

- starred (bool)
    * Whether this message is starred in Telerivet
    * Updatable via API

- simulated (bool)
    * Whether this message is was simulated within Telerivet for testing (and not actually
        sent to or received by a real phone)
    * Read-only

- label_ids (array)
    * List of IDs of labels applied to this message
    * Read-only

- vars (Hash)
    * Custom variables stored for this message
    * Updatable via API

- error_message
    * A description of the error encountered while sending a message. (This field is
        omitted from the API response if there is no error message.)
    * Updatable via API

- external_id
    * The ID of this message from an external SMS gateway provider (e.g. Twilio or Nexmo),
        if available.
    * Read-only

- price
    * The price of this message, if known. By convention, message prices are negative.
    * Read-only

- price_currency
    * The currency of the message price, if applicable.
    * Read-only

- mms_parts (array)
    * A list of parts in the MMS message, the same as returned by the
        [getMMSParts](#Message.getMMSParts) method.

        Note: This property is only present when retrieving an individual
        MMS message by ID, not when querying a list of messages. In other cases, use
        [getMMSParts](#Message.getMMSParts).
    * Read-only

- phone_id (string, max 34 characters)
    * ID of the phone that sent or received the message
    * Read-only

- contact_id (string, max 34 characters)
    * ID of the contact that sent or received the message
    * Read-only

- project_id
    * ID of the project this contact belongs to
    * Read-only

Instance Method Summary collapse

Methods inherited from Entity

#get, #initialize, #load_data, #set, #to_s, #vars

Constructor Details

This class inherits a constructor from Telerivet::Entity

Instance Method Details

#add_label(label) ⇒ Object

Adds a label to the given message.

Arguments:

- label (Telerivet::Label)
    * Required


137
138
139
140
# File 'lib/telerivet/message.rb', line 137

def add_label(label)
    @api.do_request("PUT", label.get_base_api_path() + "/messages/" + get('id'));
    @label_ids_set[label.id] = true
end

#contact_idObject



275
276
277
# File 'lib/telerivet/message.rb', line 275

def contact_id
    get('contact_id')
end

#contentObject



227
228
229
# File 'lib/telerivet/message.rb', line 227

def content
    get('content')
end

#deleteObject

Deletes this message.



187
188
189
# File 'lib/telerivet/message.rb', line 187

def delete()
    @api.do_request("DELETE", get_base_api_path())
end

#directionObject



195
196
197
# File 'lib/telerivet/message.rb', line 195

def direction
    get('direction')
end

#error_messageObject



247
248
249
# File 'lib/telerivet/message.rb', line 247

def error_message
    get('error_message')
end

#error_message=(value) ⇒ Object



251
252
253
# File 'lib/telerivet/message.rb', line 251

def error_message=(value)
    set('error_message', value)
end

#external_idObject



255
256
257
# File 'lib/telerivet/message.rb', line 255

def external_id
    get('external_id')
end

#from_numberObject



219
220
221
# File 'lib/telerivet/message.rb', line 219

def from_number
    get('from_number')
end

#get_base_api_pathObject



283
284
285
# File 'lib/telerivet/message.rb', line 283

def get_base_api_path()
    "/projects/#{get('project_id')}/messages/#{get('id')}"
end

#get_mmspartsObject

Retrieves a list of MMS parts for this message (empty for non-MMS messages).

Each MMS part in the list is an object with the following properties:

  • cid: MMS content-id

  • type: MIME type

  • filename: original filename

  • size (int): number of bytes

  • url: URL where the content for this part is stored (secret but

publicly accessible, so you could link/embed it in a web page without having to re-host it yourself)

Returns:

array


173
174
175
# File 'lib/telerivet/message.rb', line 173

def get_mmsparts()
    return @api.do_request("GET", get_base_api_path() + "/mms_parts")
end

#has_label?(label) ⇒ Boolean

Returns true if this message has a particular label, false otherwise.

Arguments:

- label (Telerivet::Label)
    * Required

Returns:

bool

Returns:

  • (Boolean)


125
126
127
128
# File 'lib/telerivet/message.rb', line 125

def has_label?(label)
    load_data()
    return @label_ids_set.has_key?(label.id)
end

#idObject



191
192
193
# File 'lib/telerivet/message.rb', line 191

def id
    get('id')
end

#label_idsObject



243
244
245
# File 'lib/telerivet/message.rb', line 243

def label_ids
    get('label_ids')
end

#message_typeObject



203
204
205
# File 'lib/telerivet/message.rb', line 203

def message_type
    get('message_type')
end

#mms_partsObject



267
268
269
# File 'lib/telerivet/message.rb', line 267

def mms_parts
    get('mms_parts')
end

#phone_idObject



271
272
273
# File 'lib/telerivet/message.rb', line 271

def phone_id
    get('phone_id')
end

#priceObject



259
260
261
# File 'lib/telerivet/message.rb', line 259

def price
    get('price')
end

#price_currencyObject



263
264
265
# File 'lib/telerivet/message.rb', line 263

def price_currency
    get('price_currency')
end

#project_idObject



279
280
281
# File 'lib/telerivet/message.rb', line 279

def project_id
    get('project_id')
end

#remove_label(label) ⇒ Object

Removes a label from the given message.

Arguments:

- label (Telerivet::Label)
    * Required


149
150
151
152
153
154
# File 'lib/telerivet/message.rb', line 149

def remove_label(label)
    @api.do_request("DELETE", label.get_base_api_path() + "/messages/" + get('id'))
    if @label_ids_set.has_key?(label.id)
        @label_ids_set.delete(label.id)
    end
end

#saveObject

Saves any fields that have changed for this message.



180
181
182
# File 'lib/telerivet/message.rb', line 180

def save()
    super
end

#set_data(data) ⇒ Object



288
289
290
291
292
293
294
295
296
# File 'lib/telerivet/message.rb', line 288

def set_data(data)
    super
    
    @label_ids_set = {}
    
    if data.has_key?('label_ids')
        data['label_ids'].each { |id| @label_ids_set[id] = true }
    end
end

#simulatedObject



239
240
241
# File 'lib/telerivet/message.rb', line 239

def simulated
    get('simulated')
end

#sourceObject



207
208
209
# File 'lib/telerivet/message.rb', line 207

def source
    get('source')
end

#starredObject



231
232
233
# File 'lib/telerivet/message.rb', line 231

def starred
    get('starred')
end

#starred=(value) ⇒ Object



235
236
237
# File 'lib/telerivet/message.rb', line 235

def starred=(value)
    set('starred', value)
end

#statusObject



199
200
201
# File 'lib/telerivet/message.rb', line 199

def status
    get('status')
end

#time_createdObject



211
212
213
# File 'lib/telerivet/message.rb', line 211

def time_created
    get('time_created')
end

#time_sentObject



215
216
217
# File 'lib/telerivet/message.rb', line 215

def time_sent
    get('time_sent')
end

#to_numberObject



223
224
225
# File 'lib/telerivet/message.rb', line 223

def to_number
    get('to_number')
end