Class: Telerivet::Contact
Overview
Fields:
- id (string, max 34 characters)
* ID of the contact
* Read-only
- name
* Name of the contact
* Updatable via API
- phone_number (string)
* Phone number of the contact
* Updatable via API
- time_created (UNIX timestamp)
* Time the contact was added in Telerivet
* Read-only
- time_updated (UNIX timestamp)
* Time the contact was last updated in Telerivet
* Read-only
- send_blocked (bool)
* True if Telerivet is blocked from sending messages to this contact
* Updatable via API
- conversation_status
* Current status of the conversation with this contact
* Allowed values: closed, active, handled
* Updatable via API
- last_message_time (UNIX timestamp)
* Last time the contact sent or received a message (null if no messages have been sent
or received)
* Read-only
- last_incoming_message_time (UNIX timestamp)
* Last time a message was received from this contact
* Read-only
- last_outgoing_message_time (UNIX timestamp)
* Last time a message was sent to this contact
* Read-only
- message_count (int)
* Total number of non-deleted messages sent to or received from this contact
* Read-only
- incoming_message_count (int)
* Number of messages received from this contact
* Read-only
- outgoing_message_count (int)
* Number of messages sent to this contact
* Read-only
- last_message_id
* ID of the last message sent to or received from this contact (null if no messages
have been sent or received)
* Read-only
- default_route_id
* ID of the basic route (phone) or custom route that Telerivet will use by default to
send messages to this contact (null if using project default route)
* Updatable via API
- group_ids (array of strings)
* List of IDs of groups that this contact belongs to
* Read-only
- vars (Hash)
* Custom variables stored for this contact
* Updatable via API
- project_id
* ID of the project this contact belongs to
* Read-only
Instance Method Summary collapse
-
#add_to_group(group) ⇒ Object
Adds this contact to a group.
- #conversation_status ⇒ Object
- #conversation_status=(value) ⇒ Object
- #default_route_id ⇒ Object
- #default_route_id=(value) ⇒ Object
-
#delete ⇒ Object
Deletes this contact.
- #get_base_api_path ⇒ Object
- #group_ids ⇒ Object
- #id ⇒ Object
- #incoming_message_count ⇒ Object
-
#is_in_group?(group) ⇒ Boolean
Returns true if this contact is in a particular group, false otherwise.
- #last_incoming_message_time ⇒ Object
- #last_message_id ⇒ Object
- #last_message_time ⇒ Object
- #last_outgoing_message_time ⇒ Object
- #message_count ⇒ Object
- #name ⇒ Object
- #name=(value) ⇒ Object
- #outgoing_message_count ⇒ Object
- #phone_number ⇒ Object
- #phone_number=(value) ⇒ Object
- #project_id ⇒ Object
-
#query_data_rows(options = nil) ⇒ Object
Queries data rows associated with this contact (in any data table).
-
#query_groups(options = nil) ⇒ Object
Queries groups for which this contact is a member.
-
#query_messages(options = nil) ⇒ Object
Queries messages sent or received by this contact.
-
#query_scheduled_messages(options = nil) ⇒ Object
Queries messages scheduled to this contact (not including messages scheduled to groups that this contact is a member of).
-
#query_service_states(options = nil) ⇒ Object
Queries this contact’s current states for any service.
-
#remove_from_group(group) ⇒ Object
Removes this contact from a group.
-
#save ⇒ Object
Saves any fields or custom variables that have changed for this contact.
- #send_blocked ⇒ Object
- #send_blocked=(value) ⇒ Object
- #set_data(data) ⇒ Object
- #time_created ⇒ Object
- #time_updated ⇒ Object
Methods inherited from Entity
#get, #initialize, #load, #set, #to_s, #vars
Constructor Details
This class inherits a constructor from Telerivet::Entity
Instance Method Details
#add_to_group(group) ⇒ Object
Adds this contact to a group.
Arguments:
- group (Telerivet::Group)
* Required
106 107 108 109 |
# File 'lib/telerivet/contact.rb', line 106 def add_to_group(group) @api.do_request("PUT", group.get_base_api_path() + "/contacts/" + get('id')); @group_ids_set[group.id] = true end |
#conversation_status ⇒ Object
424 425 426 |
# File 'lib/telerivet/contact.rb', line 424 def conversation_status get('conversation_status') end |
#conversation_status=(value) ⇒ Object
428 429 430 |
# File 'lib/telerivet/contact.rb', line 428 def conversation_status=(value) set('conversation_status', value) end |
#default_route_id ⇒ Object
460 461 462 |
# File 'lib/telerivet/contact.rb', line 460 def default_route_id get('default_route_id') end |
#default_route_id=(value) ⇒ Object
464 465 466 |
# File 'lib/telerivet/contact.rb', line 464 def default_route_id=(value) set('default_route_id', value) end |
#delete ⇒ Object
Deletes this contact.
384 385 386 |
# File 'lib/telerivet/contact.rb', line 384 def delete() @api.do_request("DELETE", get_base_api_path()) end |
#get_base_api_path ⇒ Object
476 477 478 |
# File 'lib/telerivet/contact.rb', line 476 def get_base_api_path() "/projects/#{get('project_id')}/contacts/#{get('id')}" end |
#group_ids ⇒ Object
468 469 470 |
# File 'lib/telerivet/contact.rb', line 468 def group_ids get('group_ids') end |
#id ⇒ Object
388 389 390 |
# File 'lib/telerivet/contact.rb', line 388 def id get('id') end |
#incoming_message_count ⇒ Object
448 449 450 |
# File 'lib/telerivet/contact.rb', line 448 def get('incoming_message_count') end |
#is_in_group?(group) ⇒ Boolean
Returns true if this contact is in a particular group, false otherwise.
Arguments:
- group (Telerivet::Group)
* Required
Returns:
bool
94 95 96 97 |
# File 'lib/telerivet/contact.rb', line 94 def is_in_group?(group) load() return @group_ids_set.has_key?(group.id) end |
#last_incoming_message_time ⇒ Object
436 437 438 |
# File 'lib/telerivet/contact.rb', line 436 def get('last_incoming_message_time') end |
#last_message_id ⇒ Object
456 457 458 |
# File 'lib/telerivet/contact.rb', line 456 def get('last_message_id') end |
#last_message_time ⇒ Object
432 433 434 |
# File 'lib/telerivet/contact.rb', line 432 def get('last_message_time') end |
#last_outgoing_message_time ⇒ Object
440 441 442 |
# File 'lib/telerivet/contact.rb', line 440 def get('last_outgoing_message_time') end |
#message_count ⇒ Object
444 445 446 |
# File 'lib/telerivet/contact.rb', line 444 def get('message_count') end |
#name ⇒ Object
392 393 394 |
# File 'lib/telerivet/contact.rb', line 392 def name get('name') end |
#name=(value) ⇒ Object
396 397 398 |
# File 'lib/telerivet/contact.rb', line 396 def name=(value) set('name', value) end |
#outgoing_message_count ⇒ Object
452 453 454 |
# File 'lib/telerivet/contact.rb', line 452 def get('outgoing_message_count') end |
#phone_number ⇒ Object
400 401 402 |
# File 'lib/telerivet/contact.rb', line 400 def phone_number get('phone_number') end |
#phone_number=(value) ⇒ Object
404 405 406 |
# File 'lib/telerivet/contact.rb', line 404 def phone_number=(value) set('phone_number', value) end |
#project_id ⇒ Object
472 473 474 |
# File 'lib/telerivet/contact.rb', line 472 def project_id get('project_id') end |
#query_data_rows(options = nil) ⇒ Object
Queries data rows associated with this contact (in any data table).
Arguments:
- options (Hash)
- time_created (UNIX timestamp)
* Filter data rows by the time they were created
* Allowed modifiers: time_created[min], time_created[max]
- sort
* Sort the results based on a field
* Allowed values: default
* Default: default
- sort_dir
* Sort the results in ascending or descending order
* Allowed values: asc, desc
* Default: asc
- page_size (int)
* Number of results returned per page (max 500)
* Default: 50
- offset (int)
* Number of items to skip from beginning of result set
* Default: 0
Returns:
Telerivet::APICursor (of Telerivet::DataRow)
326 327 328 329 |
# File 'lib/telerivet/contact.rb', line 326 def query_data_rows( = nil) require_relative 'datarow' @api.cursor(DataRow, get_base_api_path() + "/rows", ) end |
#query_groups(options = nil) ⇒ Object
Queries groups for which this contact is a member.
Arguments:
- options (Hash)
- name
* Filter groups by name
* Allowed modifiers: name[ne], name[prefix], name[not_prefix], name[gte], name[gt],
name[lt], name[lte]
- dynamic (bool)
* Filter groups by dynamic/non-dynamic
- sort
* Sort the results based on a field
* Allowed values: default, name
* Default: default
- sort_dir
* Sort the results in ascending or descending order
* Allowed values: asc, desc
* Default: asc
- page_size (int)
* Number of results returned per page (max 500)
* Default: 50
- offset (int)
* Number of items to skip from beginning of result set
* Default: 0
Returns:
Telerivet::APICursor (of Telerivet::Group)
242 243 244 245 |
# File 'lib/telerivet/contact.rb', line 242 def query_groups( = nil) require_relative 'group' @api.cursor(Group, get_base_api_path() + "/groups", ) end |
#query_messages(options = nil) ⇒ Object
Queries messages sent or received by this contact.
Arguments:
- options (Hash)
- direction
* Filter messages by direction
* Allowed values: incoming, outgoing
- message_type
* Filter messages by message_type
* Allowed values: sms, mms, ussd, ussd_session, call, chat, service
- source
* Filter messages by source
* Allowed values: phone, provider, web, api, service, webhook, scheduled,
integration
- starred (bool)
* Filter messages by starred/unstarred
- status
* Filter messages by status
* Allowed values: ignored, processing, received, sent, queued, failed,
failed_queued, cancelled, delivered, not_delivered, read
- time_created[min] (UNIX timestamp)
* Filter messages created on or after a particular time
- time_created[max] (UNIX timestamp)
* Filter messages created before a particular time
- external_id
* Filter messages by ID from an external provider
* Allowed modifiers: external_id[ne], external_id[exists]
- contact_id
* ID of the contact who sent/received the message
* Allowed modifiers: contact_id[ne], contact_id[exists]
- phone_id
* ID of the phone (basic route) that sent/received the message
- broadcast_id
* ID of the broadcast containing the message
* Allowed modifiers: broadcast_id[ne], broadcast_id[exists]
- scheduled_id
* ID of the scheduled message that created this message
* Allowed modifiers: scheduled_id[ne], scheduled_id[exists]
- group_id
* Filter messages sent or received by contacts in a particular group. The group must
be a normal group, not a dynamic group.
- sort
* Sort the results based on a field
* Allowed values: default
* Default: default
- sort_dir
* Sort the results in ascending or descending order
* Allowed values: asc, desc
* Default: asc
- page_size (int)
* Number of results returned per page (max 500)
* Default: 50
- offset (int)
* Number of items to skip from beginning of result set
* Default: 0
Returns:
Telerivet::APICursor (of Telerivet::Message)
202 203 204 205 |
# File 'lib/telerivet/contact.rb', line 202 def ( = nil) require_relative 'message' @api.cursor(Message, get_base_api_path() + "/messages", ) end |
#query_scheduled_messages(options = nil) ⇒ Object
Queries messages scheduled to this contact (not including messages scheduled to groups that this contact is a member of)
Arguments:
- options (Hash)
- message_type
* Filter scheduled messages by message_type
* Allowed values: sms, mms, ussd, ussd_session, call, chat, service
- time_created (UNIX timestamp)
* Filter scheduled messages by time_created
* Allowed modifiers: time_created[min], time_created[max]
- next_time (UNIX timestamp)
* Filter scheduled messages by next_time
* Allowed modifiers: next_time[min], next_time[max], next_time[exists]
- relative_scheduled_id
* Filter scheduled messages created for a relative scheduled message
- sort
* Sort the results based on a field
* Allowed values: default, next_time
* Default: default
- sort_dir
* Sort the results in ascending or descending order
* Allowed values: asc, desc
* Default: asc
- page_size (int)
* Number of results returned per page (max 500)
* Default: 50
- offset (int)
* Number of items to skip from beginning of result set
* Default: 0
Returns:
Telerivet::APICursor (of Telerivet::ScheduledMessage)
290 291 292 293 |
# File 'lib/telerivet/contact.rb', line 290 def ( = nil) require_relative 'scheduledmessage' @api.cursor(ScheduledMessage, get_base_api_path() + "/scheduled", ) end |
#query_service_states(options = nil) ⇒ Object
Queries this contact’s current states for any service
Arguments:
- options (Hash)
- id
* Filter states by id
* Allowed modifiers: id[ne], id[prefix], id[not_prefix], id[gte], id[gt], id[lt],
id[lte]
- vars (Hash)
* Filter states by value of a custom variable (e.g. vars[email], vars[foo], etc.)
* Allowed modifiers: vars[foo][ne], vars[foo][prefix], vars[foo][not_prefix],
vars[foo][gte], vars[foo][gt], vars[foo][lt], vars[foo][lte], vars[foo][min],
vars[foo][max], vars[foo][exists]
- sort
* Sort the results based on a field
* Allowed values: default
* Default: default
- sort_dir
* Sort the results in ascending or descending order
* Allowed values: asc, desc
* Default: asc
- page_size (int)
* Number of results returned per page (max 500)
* Default: 50
- offset (int)
* Number of items to skip from beginning of result set
* Default: 0
Returns:
Telerivet::APICursor (of Telerivet::ContactServiceState)
369 370 371 372 |
# File 'lib/telerivet/contact.rb', line 369 def query_service_states( = nil) require_relative 'contactservicestate' @api.cursor(ContactServiceState, get_base_api_path() + "/states", ) end |
#remove_from_group(group) ⇒ Object
Removes this contact from a group.
Arguments:
- group (Telerivet::Group)
* Required
118 119 120 121 122 123 |
# File 'lib/telerivet/contact.rb', line 118 def remove_from_group(group) @api.do_request("DELETE", group.get_base_api_path() + "/contacts/" + get('id')) if @group_ids_set.has_key?(group.id) @group_ids_set.delete(group.id) end end |
#save ⇒ Object
Saves any fields or custom variables that have changed for this contact.
377 378 379 |
# File 'lib/telerivet/contact.rb', line 377 def save() super end |
#send_blocked ⇒ Object
416 417 418 |
# File 'lib/telerivet/contact.rb', line 416 def send_blocked get('send_blocked') end |
#send_blocked=(value) ⇒ Object
420 421 422 |
# File 'lib/telerivet/contact.rb', line 420 def send_blocked=(value) set('send_blocked', value) end |
#set_data(data) ⇒ Object
481 482 483 484 485 486 487 488 489 |
# File 'lib/telerivet/contact.rb', line 481 def set_data(data) super @group_ids_set = {} if data.has_key?('group_ids') data['group_ids'].each { |id| @group_ids_set[id] = true } end end |
#time_created ⇒ Object
408 409 410 |
# File 'lib/telerivet/contact.rb', line 408 def time_created get('time_created') end |
#time_updated ⇒ Object
412 413 414 |
# File 'lib/telerivet/contact.rb', line 412 def time_updated get('time_updated') end |