Search code examples
salesforcetwiliovisualforceapex

Unable to Receive the SMS via twilio


I have twilio phone number,Visual force page and Controller.I have reference Document I have followed.I send an sms via twilio but unable to receive the sms. Customer Send an sms to twilio number it can revert back the sms but unable to receive the sms details in Salesforce Apex

Visual force page

<apex:page controller="TwilioRequestControllerContacts" action="{!init}" showHeader="false" sidebar="false">
    <center>
        <apex:pageBlock title="Twilio Request Listener"></apex:pageBlock>          
    </center>
</apex:page>

Controller

public with sharing class TwilioRequestControllerContacts 
    {
        public String fromNumber      = ApexPages.currentPage().getParameters().get('From');
        public String toNumber        = ApexPages.currentPage().getParameters().get('To');
        public String body            = ApexPages.currentPage().getParameters().get('Body');
        public PageReference init()
        {
        try
        {           
           System.debug('STEP 0 FROM: ==========>' + fromNumber); 
           System.debug('STEP 1 TO: ===============>' + toNumber);
           System.debug('STEP 2 BODY: ==========>' + body); 
IF(fromNumber != NULL && toNumber = !NULL){
Case c = new Case(Subject = toNumber+fromNumber,Description =body);
insert c;
}

          }
catch(exception e){}
        RETURN null;
       }  
    }

Here SMS conformation sent dynamically while customer send an sms it is ok. But unable to receive the SMS details. I am doing correct way or not can some one please help me


Solution

  • Finally I have created a Case while Customer Sent an SMS twilio Phone number.

    Steps:

    • After installing Twilio in Sandbox, we need to create a Visualforce page and one Controller as specified.
    • Create a Force.com Site and add your Visualforce page to your site. Then give the site url(https://sandbox.force.com/sms).

    Path :Setup > Developer > "New" Site Url

    Note : The Site Url and Twilio Account SMS Url must and should be same other wise the HTTP post request will not post to your Visualforce page. Twilio Account SMS Request URL

    • Give the Site access to the Controller and the Case Object. From the Site detail page, click Public Access Settings to visit the Site's guest user profile. Enable Read and Edit access on the Case Object. Add the controller Apex Class to the Enabled Apex Class Access list.
    • Create a Remote Site Settings in Sandbox i.e Endpoint Url for the Twilio API.

    Path :Setup > Administer > Security Controls > Remote Site Settings > "New Remote Site" End point Url

    Then send an SMS to your Twilio phone number. It will create a new case in the Sandbox. It is amazing concept of Twilio API for the Salesforce.