class Telerivet::Message
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, service * Read-only - source * How the message originated within Telerivet * Allowed values: phone, provider, web, api, service, webhook, scheduled, integration * 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 - time_updated (UNIX timestamp) * The time that the message was last updated in Telerivet. * 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 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 - priority (int) * Priority of this message. Telerivet will attempt to send messages with higher priority numbers first. Only defined for outgoing messages. * Read-only - 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 (number) * The price of this message, if known. * Read-only - price_currency * The currency of the message price, if applicable. * Read-only - duration (number) * The duration of the call in seconds, if known, or -1 if the call was not answered. * Read-only - ring_time (number) * The length of time the call rang in seconds before being answered or hung up, if known. * Read-only - audio_url * For voice calls, the URL of an MP3 file to play when the contact answers the call * Read-only - tts_lang * For voice calls, the language of the text-to-speech voice * Allowed values: en-US, en-GB, en-GB-WLS, en-AU, en-IN, da-DK, nl-NL, fr-FR, fr-CA, de-DE, is-IS, it-IT, pl-PL, pt-BR, pt-PT, ru-RU, es-ES, es-US, sv-SE * Read-only - tts_voice * For voice calls, the text-to-speech voice * Allowed values: female, male * 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 - track_clicks (boolean) * If true, URLs in the message content are short URLs that redirect to a destination URL. * Read-only - short_urls (array) * For text messages containing short URLs, this is an array of objects with the properties `short_url`, `link_type`, and `time_clicked` (the first time that URL was clicked). If `link_type` is "redirect", the object also contains a `destination_url` property. If `link_type` is "media", the object also contains an `media_index` property (the index in the media array). If `link_type` is "service", the object also contains a `service_id` property. This property is undefined for messages that do not contain short URLs. * Read-only - media (array) * For text messages containing media files, this is an array of objects with the properties `url`, `type` (MIME type), `filename`, and `size` (file size in bytes). Unknown properties are null. This property is undefined for messages that do not contain media files. Note: For files uploaded via the Telerivet web app, the URL is temporary and may not be valid for more than 1 day. * Read-only - time_clicked (UNIX timestamp) * If the message contains any short URLs, this is the first time that a short URL in the message was clicked. This property is undefined for messages that do not contain short URLs. * Read-only - service_id (string, max 34 characters) * ID of the service that handled the message (for voice calls, the service defines the call flow) * Read-only - phone_id (string, max 34 characters) * ID of the phone (basic route) 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 - route_id (string, max 34 characters) * ID of the custom route that sent the message (if applicable) * Read-only - broadcast_id (string, max 34 characters) * ID of the broadcast that this message is part of (if applicable) * Read-only - scheduled_id (string, max 34 characters) * ID of the scheduled message that created this message is part of (if applicable) * Read-only - user_id (string, max 34 characters) * ID of the Telerivet user who sent the message (if applicable) * Read-only - project_id * ID of the project this contact belongs to * Read-only
Public Instance Methods
Adds a label to the given message.
Arguments:
- label (Telerivet::Label) * Required
# File lib/telerivet/message.rb, line 220 def add_label(label) @api.do_request("PUT", label.get_base_api_path() + "/messages/" + get('id')); @label_ids_set[label.id] = true end
# File lib/telerivet/message.rb, line 399 def audio_url get('audio_url') end
# File lib/telerivet/message.rb, line 447 def broadcast_id get('broadcast_id') end
Cancels sending a message that has not yet been sent. Returns the updated message object. Only valid for outgoing messages that are currently in the queued, retrying, or cancelled states. For other messages, the API
will return an error with the code 'not_cancellable'.
Returns:
Telerivet::Message
# File lib/telerivet/message.rb, line 295 def cancel() require_relative 'message' Message.new(@api, @api.do_request("POST", get_base_api_path() + "/cancel")) end
# File lib/telerivet/message.rb, line 439 def contact_id get('contact_id') end
# File lib/telerivet/message.rb, line 347 def content get('content') end
Deletes this message.
# File lib/telerivet/message.rb, line 303 def delete() @api.do_request("DELETE", get_base_api_path()) end
# File lib/telerivet/message.rb, line 311 def direction get('direction') end
# File lib/telerivet/message.rb, line 391 def duration get('duration') end
# File lib/telerivet/message.rb, line 371 def error_message get('error_message') end
# File lib/telerivet/message.rb, line 375 def error_message=(value) set('error_message', value) end
# File lib/telerivet/message.rb, line 379 def external_id get('external_id') end
# File lib/telerivet/message.rb, line 339 def from_number get('from_number') end
# File lib/telerivet/message.rb, line 463 def get_base_api_path() "/projects/#{get('project_id')}/messages/#{get('id')}" end
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
# File lib/telerivet/message.rb, line 256 def get_mmsparts() return @api.do_request("GET", get_base_api_path() + "/mms_parts") end
Returns true if this message has a particular label, false otherwise.
Arguments:
- label (Telerivet::Label) * Required
Returns:
bool
# File lib/telerivet/message.rb, line 208 def has_label?(label) load() return @label_ids_set.has_key?(label.id) end
# File lib/telerivet/message.rb, line 307 def id get('id') end
# File lib/telerivet/message.rb, line 363 def label_ids get('label_ids') end
# File lib/telerivet/message.rb, line 423 def media get('media') end
# File lib/telerivet/message.rb, line 319 def message_type get('message_type') end
# File lib/telerivet/message.rb, line 411 def mms_parts get('mms_parts') end
# File lib/telerivet/message.rb, line 435 def phone_id get('phone_id') end
# File lib/telerivet/message.rb, line 383 def price get('price') end
# File lib/telerivet/message.rb, line 387 def price_currency get('price_currency') end
# File lib/telerivet/message.rb, line 367 def priority get('priority') end
# File lib/telerivet/message.rb, line 459 def project_id get('project_id') end
Removes a label from the given message.
Arguments:
- label (Telerivet::Label) * Required
# File lib/telerivet/message.rb, line 232 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
Resends a message, for example if the message failed to send or if it was not delivered. If the message was originally in the queued, retrying, failed, or cancelled states, then Telerivet
will return the same message object. Otherwise, Telerivet
will create and return a new message object.
Arguments:
- options (Hash) - route_id * ID of the phone or route to send the message from
Returns:
Telerivet::Message
# File lib/telerivet/message.rb, line 282 def resend(options = nil) require_relative 'message' Message.new(@api, @api.do_request("POST", get_base_api_path() + "/resend", options)) end
# File lib/telerivet/message.rb, line 395 def ring_time get('ring_time') end
# File lib/telerivet/message.rb, line 443 def route_id get('route_id') end
Saves any fields that have changed for this message.
Telerivet::Entity#save
# File lib/telerivet/message.rb, line 263 def save() super end
# File lib/telerivet/message.rb, line 451 def scheduled_id get('scheduled_id') end
# File lib/telerivet/message.rb, line 431 def service_id get('service_id') end
Telerivet::Entity#set_data
# File lib/telerivet/message.rb, line 468 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
# File lib/telerivet/message.rb, line 419 def short_urls get('short_urls') end
# File lib/telerivet/message.rb, line 359 def simulated get('simulated') end
# File lib/telerivet/message.rb, line 323 def source get('source') end
# File lib/telerivet/message.rb, line 351 def starred get('starred') end
# File lib/telerivet/message.rb, line 355 def starred=(value) set('starred', value) end
# File lib/telerivet/message.rb, line 315 def status get('status') end
# File lib/telerivet/message.rb, line 427 def time_clicked get('time_clicked') end
# File lib/telerivet/message.rb, line 327 def time_created get('time_created') end
# File lib/telerivet/message.rb, line 331 def time_sent get('time_sent') end
# File lib/telerivet/message.rb, line 335 def time_updated get('time_updated') end
# File lib/telerivet/message.rb, line 343 def to_number get('to_number') end
# File lib/telerivet/message.rb, line 415 def track_clicks get('track_clicks') end
# File lib/telerivet/message.rb, line 403 def tts_lang get('tts_lang') end
# File lib/telerivet/message.rb, line 407 def tts_voice get('tts_voice') end
# File lib/telerivet/message.rb, line 455 def user_id get('user_id') end