You need to sign in to do that
Don't have an account?
Popup page when a Twilio call comes in salesforce
Hi,
I have successfully integrated Twilio with salesforce, contacts can call the twilio number and get routed accordingly and speak to a company representative, also call and SMS can be made from salesforce.
What I am looking for is when an outside caller calls the twilio number a small popup window should display the contact's details.
How can I achieve this functionality?
Architecture:
================
Triggering point: Visualforce Page, tied to a Apex Class.
The caller is requested to press "1" to speak to someone, right now the owner of the record is automatically called. (at this point the pop up window should be displayed. which is my requirement)
Page 1 is first invoked which is linked to a controller and the caller is greeted with name and directed to press a 1, when the caller presses 1 it is directed to Page 2 which automatically calls the owner of the contact record.
Page 1:
<apex:page controller="KVTwilioController" showheader="false" contentType="text/xml" >{! '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' } <Response> <Say>Hello {!name}</Say> <Say>Welcome to Neuberger Berman.</Say> <Gather numDigits="1" action="KVTwilioHandleKeyPage" method="POST"> <Say>To speak to a real person, press 1. Press any other key to start over.</Say> </Gather> </Response> </apex:page>
Controller controlling Page 1:
public class KVTwilioController { public KVTwilioController() {} /* return TwiML */ public String getName() { // if the caller is known, then greet them by name // otherwise, consider them just another monkey String name = 'Hi'; String fromPhone = ApexPages.currentPage().getParameters().get('From'); if (fromPhone!=null) { System.debug('~~~~~~~~ KVTwilioController : fromPhone : ' + fromPhone); // remove the country prefix for Phone field search if (fromPhone.startsWith('+1')) fromPhone = fromPhone.substring(2); // search Lead and Contact phone number fields List<List<SObject>> results = [FIND :fromPhone IN Phone FIELDS RETURNING Contact(FirstName, LastName), Lead(FirstName, LastName) LIMIT 1]; // extract the name if there’s a match if (!results[0].isEmpty()) { Contact r = (Contact)results[0][0]; name = r.firstName + ' ' + r.lastName; System.debug('~~~~~~~~ KVTwilioController : Contact Name : ' + name); } else if (!results[1].isEmpty()) { Lead r = (Lead)results[1][0]; name = r.firstName + ' ' + r.lastName; System.debug('~~~~~~~~ KVTwilioController : Lead Name : ' + name); } } return name; } // if the caller pressed anything but 1 send them back public PageReference getHandleUserInput() { PageReference p = new PageReference('/apex/KVTwilioHandleKeyPage'); if (ApexPages.currentPage().getParameters().get('Digits') == '1'){ } return p; } }
Page 2:
<apex:page controller="KVTwilioHandleKeyController" showheader="false" contentType="text/xml" >{! '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' } <Response> <Dial>{!dialNumber}</Dial> <Gather action="KVPopUpPage" /> <Say>The call failed or the remote party hung up. Goodbye.</Say> </Response> </apex:page>
Controller controlling page 2
public class KVTwilioHandleKeyController { public String getDialNumber() { // if the caller is known, then find their owner's phone number String dialNumber; String fromPhone = ApexPages.currentPage().getParameters().get('From'); if (fromPhone!=null) { // remove the country prefix for Phone field search if (fromPhone.startsWith('+1')) fromPhone = fromPhone.substring(2); // search Lead and Contact phone number fields List<List<SObject>> results = [FIND :fromPhone IN Phone FIELDS RETURNING Contact(Owner.Phone), Lead(Owner.Phone) LIMIT 1]; // extract the owner phone if there’s a match if (!results[0].isEmpty()) { Contact r = (Contact)results[0][0]; if (r.owner!=null && r.owner.phone!=null) dialNumber = r.owner.phone; } else if (!results[1].isEmpty()) { Lead r = (Lead)results[1][0]; if (r.owner!=null && r.owner.phone!=null) dialNumber = r.owner.phone; } } return dialNumber; } // if the caller pressed anything but 1 send them back public String redirect() { if (ApexPages.currentPage().getParameters().get('Digits') != '1') return '/KVTwilioPage'; return null; } }
Where you able to find answer for this?
Please help me on the same