To help you with your entries for the Twilio Developer Challenge that runs until Dreamforce I’ve put together a quick demo of a Click To Call function for Salesforce CRM. Basically, the demo adds a link to the Contact Page Layout and will connect your phone to the Contact’s Phone with a simple click.
Take a look at the controller class before we fill in the configuration data. We’re using the TwilioRestClient and TwilioRestResponse classes from the Twilioforce library to make our calls a bit more efficiently.
public PageReference ClickToCallAction() {
TwilioRestClient client = new TwilioRestClient(CONFIG.AccountSID, CONFIG.AuthToken, null);
Mapparams = new Map ();
params.put('Caller', CONFIG.OutGoingCallerID);
params.put('Called', TwilioTarget);
params.put('Url', CONFIG.ClickToCallURL + '?Called=' + EncodingUtil.urlEncode(contact.phone, 'UTF-8'));
TwilioRestResponse response;
try {
response = client.request('/'+CONFIG.APIVERSION+'/Accounts/'+CONFIG.AccountSID+'/Calls', 'POST', params);
ReturnCode = 'Called Placed: Connecting ' + TwilioTarget + ' with ' + contact.Phone;
return null;
} catch (Exception e) {
ReturnCode = 'ERROR: ' + e;
return null;
}
}
1) Click on the TwilioConfig tab and create a new record. (The demo has a LIMIT 1 query so you can only have a single working config record).
2) Enter your Twilio developer info. Add an OutGoing Caller ID number that Twilio has validated.
3) Enter the URL for the Force.com Sites entry you created above.
4) Go to your User record and add your preferred phone number for Twilio calls
The package has a new page layout for Contact. If everything was done correctly you should see something that resembles the following illustration:
Clicking on the number will kick off the following events:
1) Make a REST call to Twilio’s /Calls method requesting an outbound call to the phone number you entered on your User account record. (Sending the Force.com Sites URL for callback)
2) Twilio places the call (and greets you w/ the demo script if you haven’t set up your paid account yet) and fetches the TwiML in the Force.com Sites Page.
3) The
Hopefully, this will give you a headstart on your developer challenge application. Good luck and let me know if you have any questions.