+ Start a Discussion
Ramesh SomalagariRamesh Somalagari 

How to get SMS request via twilio

I have a class that can access the site url in the salesforce.
The site url "https://somesalesforce.com/smsToApex" and same as the twilio account sms URL but this class can't called.User-added image I have reference https://developer.salesforce.com/blogs/developer-relations/2012/04/sms-to-lead-with-the-twilio-library-for-salesforce.html#comment-1449666487 .The twilio SMS url correct are not how to check?The Twilio account SMS url and salesforce site url are same as of now.Whenever SMS is came via twilio then automatically Case is createin the sandbox.But here not happened.I doing correct producer are not?.Can someone please help me.How to resolve this problem.I have checked the twilio sms url like this "https://somesalesforce.com/service/apexrest/smsToApex".which url I will give both Salesforce site url, Twilio SMS url.


    @RestResource(urlMapping='/smsToApex')
    global class smsToApex
    {  
        Static TwilioAccount account = TwilioAPI.getDefaultAccount();        
        @HttpPost
        global static void incomingSMS()
        {       
            // This will error out with System.LimitException if we would exceed
            // our daily email limit
            Messaging.reserveSingleEmailCapacity(1);
   
            String expectedSignature = RestContext.request.headers.get('X-Twilio-Signature');
            system.debug('ES' + expectedSignature);
            String url = 'https://' + RestContext.request.headers.get('Host') + '/services/apexrest' + RestContext.request.requestURI;
            Map <String, String> params = RestContext.request.params;
           system.debug('smsToApex========>'+params);
            // Validate signature
            if (!TwilioAPI.getDefaultClient().validateRequest(expectedSignature, url, params)) {
                RestContext.response.statusCode = 403;
                RestContext.response.responseBody = Blob.valueOf('Failure! Rcvd '+expectedSignature+'\nURL '+url/*+'\nHeaders'+RestContext.request.headers*/);
               
                return;
            }      
            RestContext.response.responseBody = Blob.valueOf('ok');       
            String caseFrom = params.get('From');
             String caseTo = params.get('To');
            String   caseBody = params.get('Body');         
              System.debug('Step 4 smsToApex caseFrom==>'+caseFrom);
              System.debug('Step 5 smsToApex caseTo===>'+caseTo);
              System.debug('Step 6 smsToApex caseBody===>'+caseBody);         
               Case ca = new Case();
                ca.Subject = 'Test smsToApex caseFrom'+caseFrom;
                ca.Description = 'Test smsToApex caseBody'+caseBody+','+caseTo;
                ca.Origin = 'Phone';
                INSERT ca;                 
         }                      
    }



Jean-NoelJean-Noel
In the Twilio log, can you see that your call of the APi were succeful ?
If the call is successful, you'll need to check Salesforce log.