Contents
If you’re reading this then you’ve probably already read the Lightning Open CTI post on the Salesforce developer blog and wondering how the heck get outbound calling working with Twilio and the Salesforce Open CTI call center.
Disclaimer: I’m not a Salesforce Lightning dev, and would love for someone to fork and improve on the demo provided. Twilio has given everyone a great platform and there seems to be a large gap when it comes to “good” telephony solutions for Salesforce. Most providers charge a lot and have a minimum number of licenses for the most basic packages.
Install the Salesforce Packages:
Both of the follow packages are unmanaged but will take only minutes to get installed in your Salesforce instance.
Install the latest Twilio Helper Package
- https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1a000000AQzf
- (Github reference https://github.com/twilio/twilio-salesforce)
Install the Open CTI demo app
- https://login.salesforce.com/packaging/installPackage.apexp?p0=04t41000000bSXh
- (Github reference https://github.com/developerforce/open-cti-demo-adapter)
Update call center settings:
There was some confusion in the first tutorial which took me hours to debug, but as you can see below, the correct settings for your Twilio details should be listed in the below boxes.
- Navigate to Setup inside Salesforce
- In the sidebar, navigate to Build > Customize > Call Center > Call Centers
- Select the newly created call center called “Demo Call Center Adapter”
- Update the following fields
- CTI Provider should be TwilioProvider (no spaces)
- Provider Account/Auth Token can be both found on the main page of your Twilio account
- Provider Caller Number is the phone number you have bought in Twilio
Assign your users to the call center:
On the same page under your call center Twilio settings, add in the users which will be allowed to use this service.
Update the APEX code:
The code below is static and you can simply overwrite the existing code in the file to ensure you’ve got everything 100% correct. This will allow calls to be made to the “TwilioProvider” and not the Demo call which is set as default.
- Navigate to Setup inside Salesforce
- In the sidebar, navigate to Develop > Installed Packages
- Select the package “Open CTI Lightning Demo Adapter”
- Select View Componants
- Scroll down and open “SoftphoneProviderHelper”
- Edit the file and paste in the below code. Alternatively, you can simply remove the comments from the Twilio class.
- Save the new changes to your config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
public class SoftphoneProviderHelper { public class ProviderFactory { public ProviderFactory(){} public SoftphoneProviderHelper.SoftphoneProvider newProvider(String className) { Type providerImpl = Type.forName(className); if (providerImpl == null){ return null; } return (SoftphoneProviderHelper.SoftphoneProvider) providerImpl.newInstance(); } } public class CallResult { public String status; public String toNumber; public String fromNumber; public String accoundId; public String provider; public String error; public String duration; public DateTime startTime; } public interface SoftphoneProvider { CallResult makeCall(String account, String token, String toNumber, String fromNumber); } /* * Example of a call provider, using the Twilio Helper Package */ public class TwilioProvider implements SoftphoneProvider { public CallResult makeCall(String account, String token, String toNumber, String fromNumber) { TwilioRestClient client = new TwilioRestClient(account, token); Map<String,String> params = new Map<String,String> { 'To' => toNumber, 'From' => fromNumber, 'Url' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient' }; TwilioCall call = client.getAccount().getCalls().create(params); CallResult result = new CallResult(); result.status = call.getStatus(); return result; } } } |
Add Open CTI to your Layout:
For this you will need to be using Salesforce Lightning and a view with console.
- Navigate to Setup inside Salesforce
- In the sidebar, navigate to Apps > Manage Apps
- Select your app which has the new Lightning Console, or create a new app
- Add the “Open CTI Softphone” to your Utility bar
Test everything out:
If everything is working, you should now see “Phone” in your Utility bar. Simply click “Sign in” to start your testing.
Open up a contact and select a phone number field to test your dialing out
Known Bugs:
We’ve already noticed some bugs which you might want to make a note of.
- If you see this error “Uncaught Error: Unable to make a call. Contact your admin. throws at components/c/callInitiatedPanel.js:57:37” It is either because the call has failed or there no associated contact has been found. Issue number 3 can be tracked on Github.
- There seems to be some issues ending a call at times where the End button doesn’t in fact terminate the call.
- Yet to figure out inbound calling (more development required)
Take away?
Even with the few bugs, seeing this sort of implementation is a really strong step in an easy way to setup the most basic outbound calling for your Salesforce users. Would love to hear what you think in the comments below and if anyone can make some other easy to follow guides on how to customize Salesforce’s Open CTI!
I’ve made some progress on a Twilio script that completes the example and connects a user’s phone with the destination. I’d like to collaborate with others on a Force.com classic version and make the TwiML generic. I have been unable to raise David on email. Are there others pursuing this? -Eric [email protected]
Hi Eric,
I also haven’t been able to get a response from David. He does seem to be the guru in this area as well. I agree 100% that it would be good to have something generic and easy to use for SF classic and lightning. Classic is good, but everything is slowly moving towards LEX, so better development is pushed down that path at the same time.
Would be great if there are some experts out there that can contribute and fork the current github repo.
Hi All,
I’ve followed all the above steps but facing the same issue which is mentioned in *Known Bugs:* section.
Uncaught Error: Unable to make a call. Contact your admin. throws at https://alu–tfsb2–c.cs85.visual.force.com/components/c/callInitiatedPanel.js:57:37
Please help me with fixing this issue!
Thanks!
I just did it completely follow your guide. but it seems not work and no errors
Hi Sam,
Do you see the incoming call in the twilio logs?
If you can see the call, there could be a problem with your twilio configuration.
Best,
MooMaster
Noticed you can’t edit the Apex code in production. Any suggestions or does anyone know the url to sue for connecting to twilio?
Not working in Classic 🙁 demoAdapterPage2 is not found.
I had the same issue: demoAdapterPage2 is not found.
Please, someone could help me???
Hi Thaisa,
I haven’t tried this in classic for a long time now. I’m actually currently using https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000EJH4yUAH
Which is the Amazon Connect configuration. Works perfect with a bit of playing with the configuration. Maybe worth a shot if you just need basic calling inbound/outbound. Pricing is about the same as what you would be paying for Twilio.
Best,
MooMaster
Hi
I have installed open cti lightning as per guidelines but i cant get inbound calls. what are the changes we need to do for inbound calls.
Hi,
I want to implement inbound call for open cti lightning but i am unable to figure it out how to implement this?
Looking forward to your response.
Hey so finally was able to have everything “running” but when I make a call to a number (my mobile) and I pick up, i just hear music, what i need to change in order to allow to have a conversation?
the SoftphoneProviderHelper has this map parameter ‘Url’ => ‘http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient’ that is the music, so I am guessing this needs to be change?
Hi @Fabian: I was able to complete similar to what you achieved. Did you find out what we need to do further? How do we actually place a real call?
I’ve followed the above guidelines but facing the same issue which is given in the Known Bugs section,
Uncaught Error: Unable to make a call. Contact your admin. throws at https://alu–tfsb2–c.cs85.visual.force.com/components/c/callInitiatedPanel.js:57:37
Please help! Need suggestions on how to fix it!
Thanks!
Hi All,
I’ve followed all the above steps but facing the same issue which is mentioned in *Known Bugs:* section.
Uncaught Error: Unable to make a call. Contact your admin. throws at https://alu–tfsb2–c.cs85.visual.force.com/components/c/callInitiatedPanel.js:57:37
Please help me with fixing this issue!
Thanks!
Stuck at the same place. Any progress at your end folks?
I do get an outbound call but when I pick up the call, the only thing I hear is music, not sure what needs to be changed in Apex code or at Twilio end to make it work. Any help is appreciated. Thanks