Messages
The messages object contains functions related to previewing and sending messages
add_recipient()
Add a recipient and, optionally, merge data to your message
Function Declaration
public function add_recipient($phone_number, $merge_data = false);
Example Code
$textplode = new Textplode('API_KEY');
$merge_data = array('{FNAME}', 'Contact');
$textplode->messages->add_recipient('440000000000', $merge_data);
Example Response
This function does not return anything
list_recipients()
Returns either a JSON encoded string or an array containing all recipients and merge data added to the message so far
Function Declaration
public function list_recipients($type = 'array');
Example Code
$textplode = new Textplode('API_KEY');
$merge_data1 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'One') );
$merge_data2 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'Two') );
$textplode->messages->add_recipient('440000000000', $merge_data1);
$textplode->messages->add_recipient('440000000001', $merge_data2);
$recipients = $textplode->messages->list_recipients('json');
Example Response
[{"phone_number":"440000000000","merge":{"{FNAME}":"Contact"},{"{LNAME}":"One"}}, {"phone_number":"440000000001","merge":{"{FNAME}":"Contact"},{"{LNAME}":"Two"}}]
clear_recipients()
Removes all recipients and merge data from the current messages object
Function Declaration
public function clear_recipients();
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->add_recipient('440000000000', null);
$textplode->messages->clear_recipients();
$recipients = $textplode->messages->list_recipients('json'); /* Should return empty JSON array */
Example Response
[{"phone_number":"440000000000","merge":{"{FNAME}":"Contact"},{"{LNAME}":"One"}}, {"phone_number":"440000000001","merge":{"{FNAME}":"Contact"},{"{LNAME}":"Two"}}]
set_message()
Sets the message to be sent. Merge tags should be added inline in this call
Function Declaration
public function set_message($message);
Example Code
$textplode = new Textplode('API_KEY');
$merge_data1 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'One') );
$merge_data2 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'Two') );
$textplode->messages->add_recipient('440000000000', $merge_data1);
$textplode->messages->add_recipient('440000000001', $merge_data2);
$recipients = $textplode->messages->list_recipients('json');
$textplode->messages->set_message("Hello {FNAME}. Welcome to Textplode");
Example Response
This function does not return anything
get_message()
Gets the currently set message including merge tags
Function Declaration
public function get_message();
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_message("Hello {FNAME}. Welcome to Textplode");
$message = $textplode->messages->get_message()
Example Response
Hello {FNAME}. Welcome to Textplode
set_from()
Sets the from name of the message
Function Declaration
public function set_from($from);
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_from("Textplode");
Example Response
This function does not return anything
get_from()
Gets the currently set from name from the message
Function Declaration
public function get_from($from);
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_from("Textplode");
$from = $textplode->messages->get_from();
Example Response
Textplode
reset()
Resets all recipients, from name and message in the messages object. This should be called after send() if sending messages in a loop.
Function Declaration
public function reset();
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_from("Textplode");
$textplode->messages->reset();
$textplode->messages->get_from(); /* Should return blank */
Example Response
This function does not return anything
test()
Parses all recipients and merge data and returns the strings along with message lengths. The root JSON response also gets passed a "longest_message" paramater that returns the length of the longest message.
Function Declaration
public function test();
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_from("Textplode");
$textplode->messages->set_message("Hello {FNAME} {LNAME}. Welcome to Textplode");
$merge_data1 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'One') );
$merge_data2 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'Two') );
$textplode->messages->add_recipient('440000000000', $merge_data1);
$textplode->messages->add_recipient('440000000001', $merge_data2);
$textplode->messages->test();
Example Response
{"errors":{"errorCode":200,"errorMessage":"OK"},"version":"v3","data":[{"phone_number":"440000000000","merged_message":"Hello Contact One! Welcome to Textplode","message_length":39},{"phone_number":"440000000001","merged_message":"Hello Contact Two! Welcome to Textplode","message_length":31}],"longest_message":39}
send()
Parses all recipients and merge data and send the resulting messages.
Function Declaration
public function send();
Example Code
$textplode = new Textplode('API_KEY');
$textplode->messages->set_from("Textplode");
$textplode->messages->set_message("Hello {FNAME} {LNAME}. Welcome to Textplode");
$merge_data1 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'One') );
$merge_data2 = array( array('{FNAME}', 'Contact'), array('{LNAME}', 'Two') );
$textplode->messages->add_recipient('440000000000', $merge_data1);
$textplode->messages->add_recipient('440000000001', $merge_data2);
$textplode->messages->send();
Example Response
{"errors":{"errorCode":200,"errorMessage":"OK"},"version":"v3","data":"sent"}