You can send messages from Apex using our Apex API. This API allows you to send messages using the Messente
class which can be accessed through the gams4sf
namespace as gams4sf.Messente.
The following methods are available with example code provided at the end of the article.
Sends a single SMS message to the provided number using the message text provided. Note the message is not stored.
global static String sendSMSMessage(String phoneNumber, String message)
Type: String
Description: The phone number you wish to send the message to in e.164 format
Type: String
Description: The message to send to the number.
Type: String
Description: The unique omnimessage_id value for this message from Messente.
Sends the same message to a set of phone numbers. Note that the message is not stored.
global static List<String> sendSMSMessages(List<String> phoneNumbers, String message)
Type: List<String>
Description: The list of phone numbers you wish to send the message to in e.164 format
Type: String
Description: The message to send to the numbers.
Type: List<String>
Description: The set of unique omnimessage_id
values for these messages from Messente.
This sends an SMS message to a number and records the sending of the message in the system as a gams4sf__Message__c
record.
global static Id sendAndLogSMSMessage(SMS message)
Type: SMS (custom Apex class, see below)
Description: A wrapper class instance that details the SMS message to be sent and recorded.
Type: Id
Description: The Id of the gams4sf__Message__c
record created for the sent message.
This sends a series of SMS messages and records the messages in the system as gams4sf__Message__c
records.
global static List<Id> sendAndLogSMSMessages(List<SMS> messages)
Type: List<SMS> (custom Apex class, see below)
Description: A list of wrapper class instances that detail the SMS messages to be sent and recorded.
Type: List<Id>
Description: The Ids of the gams4sf__Message__c
records created for the sent messages.
Sends a single Viber message to the provided number using the message text provided. Note the message is not stored.
global static String sendViberMessage(String phoneNumber, String message)
Type: String
Description: The phone number you wish to send the message to in e.164 format
Type: String
Description: The message to send to the number.
Type: String
Description: The unique omnimessage_id
value for this message from Messente.
Sends the same message to a set of phone numbers. Note that the message is not stored.
global static List<String> sendViberMessages(List<String> phoneNumbers, String message)
Type: List<String>
Description: The list of phone numbers you wish to send the message to in e.164 format
Type: String
Description: The message to send to the numbers.
Type: List<String>
Description: The set of unique omnimessage_id
values for these messages from Messente.
The SMS wrapper class wraps the details necessary to send and record SMS messages as gams4sf__Message__c records.
SMS(String recipient, String message, Id recordId)
Type: String
Description: The phone number to send the message to in e.164 format.
Type: String
Description: The message text to send to the recipient
Type: Id
Description: The Id of the record to relate the associated gams4sf__Message__c records to.
1//Send a single SMS Message - not recorded
2String singleOmnimessageId = gams4sf.Messente.sendSMSMessage('+447700123456', 'Single message');
3
4//Send the same SMS message to multiple recipients - not recorded
5List<String> multiOmniMessageIds = gams4sf.Messente.sendSMSMessages(new List<String>{'+447700123456', '+447700123457'}, 'Multiple messages');
6
7//Send a single SMS message and have it recorded against a contact
8gams4sf.Messente.SMS message = new gams4sf.Messente.SMS('+447700123456', 'Single logged message', '003WS000002jumUYAQ');
9Id singleMessageId = gams4sf.Messente.sendAndLogSMSMessage(message);
10
11//Send multiple unique SMS messages at once and have them recorded against contacts
12List<gams4sf.Messente.SMS> messages = new List<gams4sf.Messente.SMS>{
13 new gams4sf.Messente.SMS('+447700123456', 'Multiple logged messages 1', '003WS000002jumUYAQ'),
14 new gams4sf.Messente.SMS('+447700123457', 'Multiple logged messages 2', '003WS000002jumUYAQ')};
15List<Id> multiMessageIds = gams4sf.Messente.sendAndLogSMSMessages(messages);