function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alaa Aljelani 15Alaa Aljelani 15 

SMS Gateway Integration

I really need your help in understanding the integration between SMS gateway and salesforce step by step.
I'm not personally familiar with it. As I'm not from a technical background.

How can I integrate them via API? how to do this?

If anyone can give me a detailed overview about it.

Appreciated!
Raj VakatiRaj Vakati
Hi Alaa ,

You can use Twilio API to send SMS from Salesforce and to Receive as well. here is the sample code .
 
public class SendSMS {
    private static final String VERSION = '3.2.0';
    private String endpoint = 'https://api.twilio.com';
    public static final String DEFAULT_VERSION = '2010-04-01';
    public Twillo_Configuration__mdt  cmd {get;set;}
    private String accountSid;
    private String authToken;
    public String phoneNumber;
    public SMS__c smsRec {get;set;}
    public SendSMS(ApexPages.Standardcontroller controller){
        smsRec = new SMS__c();
        cmd= [Select 
              ACCOUNT_SID__c  ,AUTH_TOKEN__c  , From_Number__c 
              from Twillo_Configuration__mdt  where DeveloperName='Twillo_Configuration'];
        smsRec.From_Number__c =cmd.From_Number__c;
        
        
    }
    
    public PageReference sendSMS(){
        accountSid = cmd.ACCOUNT_SID__c;
        authToken = cmd.AUTH_TOKEN__c;
        phoneNumber = cmd.From_Number__c;    
        String responseBody = '';
        String path = endpoint + '/' + DEFAULT_VERSION + '/Accounts/' + this.accountSid + '/SMS/Messages.json';
        URL uri = new URL(path);
        String reqBody = '';
        if(smsRec.To_Number__c != Null && smsRec.Message__c != '') {
            reqBody += (reqBody=='' ? '' : '&')+ 'To' + '=' + EncodingUtil.urlEncode(string.valueOf(smsRec.To_Number__c), 'UTF-8');
            reqBody += (reqBody=='' ? '' : '&')+ 'Body' + '=' + EncodingUtil.urlEncode(smsRec.Message__c, 'UTF-8');
            reqBody += (reqBody=='' ? '' : '&')+ 'From' + '=' + EncodingUtil.urlEncode(smsRec.From_Number__c, 'UTF-8');
        } else {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Mobile Number and Text Message are required.');       
            ApexPages.addMessage(myMsg); 
        }
        Http h = new Http();
        HttpRequest request = new HttpRequest();
        
        request.setHeader('X-Twilio-Client', 'salesforce-' + VERSION);
        request.setHeader('User-Agent', 'twilio-salesforce/' + VERSION);
        request.setHeader('Accept', 'application/json');
        request.setHeader('Accept-Charset', 'utf-8');
        request.setHeader('Authorization', 'Basic '+EncodingUtil.base64Encode(Blob.valueOf(this.accountSid + ':' + this.authToken)));
        request.setEndpoint(uri.toExternalForm());
        request.setMethod('POST');
        request.setBody(reqBody);
        HttpResponse res = h.send(request);
        
        responseBody = res.getBody();
        System.debug('responseBody:::::::::::' +responseBody);     
        
        insert smsRec ;
        
        
        return null ;
    }
    
}





 
Alaa Aljelani 15Alaa Aljelani 15

Thank you Raj for sending the above code. I'm obliged to choose a local company at my country for SMS gateway.

What do you think I should ask for or know?

ValueText SMSValueText SMS
You can send SMS from salesforce but choose best option.

In 3 ways you can send SMS from Salesforce.

1. Salesforce default SMS sending
           A. Very expensive. 
           B. Some places you have to put your development efforts to make the process automatic.
           C. Limited to 5 Countries now.
2. Integrate SMS gateway.
    N number of gateways in a market where you can choose and integrate.

     Pros:
           A. SMS prices are low.
     Cons:
           A. Most of the gateways don't accept Bulk SMS in a single API call. You have to develop your system to handle those calls because it                           causes issue while you do bulk upload with data loader.
           B. For every template you have to hard code your template in apex and it is very difficult to manage.
           C. When there is a change in the template you have to edit and redeploy the code.
           D. If you want to send SMS to different countries Integration is not a good option because International SMS gateway cannot give SMS at                   local Price. 
           E. You have to invest your money and time on every SMS template creation or update.

3. You can find App in AppExchange.
          There are a few apps in AppExhnage which are providing complete automation, but few apps drain your API limits.        
   ​
        Pros : 
          A. No hard coding of Template. Like email Template you can manage SMS templates.(few are not provided)
          B. 0 Development efforts.
          D. Easy to manage templates.


        If your option is 3 ? You can have a look at our ValueText SMS App: https://goo.gl/2uBgMM  


            A. ValueText SMS app:
            B. Multi Object Support Templates.
            C. 1 API call to send up to 40k SMS.
            D. SMS from Related List.
            E. Run SMS campaign for leads.
            F. SMS via Workflow or process builder
            G. Single & Bulk SMS from any Object.
            H. No limits on Mobile Number field.
            I. SMS previews before you send.
            J. Very less price in AppExchange.
           K. Free customization 


Please mark this is an best answer if you like my post.
 
Pooja Sharma 118Pooja Sharma 118
Hi
You can use SMART SMS APP  to Send SMS from Salesforce  (https://www.girikon.com/apps/salesforce-sms-app/)
Thanks