May 13, 2023
With this salesforce tutorial, we will learn about How we can integrate Salesforce with Dialpad and How to send SMS from Salesforce using Dialpad.
We will cover the following points to achieve our goal:
What is Dialpad?
Before we start, we should know about the Dialpad. Let explore briefly.
Dialpad is a cloud-based communication platform that provides businesses with a range of voice, video, and messaging tools. Dialpad is designed to improve communication and collaboration among teams, regardless of their location or device.
Salesforce integration with Dialpad provides businesses with a powerful solution that combines the benefits of a robust cloud-based phone system with the capabilities of Salesforce's CRM platform. This integration enables businesses to streamline their communications, improve their customer engagement, and drive growth.
With the Salesforce integration, Dialpad can automatically log call and messaging data directly into Salesforce, giving sales and support teams a 360-degree view of customer interactions. This helps businesses to gain valuable insights into customer behavior and preferences, and enables them to personalize their communications for better engagement.
Let's dive into it and see how Salesforce can integrate with Dialpad.
First, we need to create an account in the Dialpad so we can use the Dialpad with Salesforce using this link: https://dialpad.com/signup
After creating an account in the Dialpad, click on the Authenticate and add the key using Add Key button like the below figure and It will generate the API key automatically.
Now we will use this auto generated API key in the Salesforce.
Here we will see How we can send SMS from Salesforce using Dialpad to the customers. To do that, we will create an apex class with a method to get the relevant user id from the Dialpad account. The purpose of getting the relevant user's id from Dialpad is that in which user's context we want to send the SMS to the customer.
public class GetUser {
//This method will get the relevant user id from the Dialpad account. Here we are pasing the email to dialpad account and
//get the id of respective user in salesforce.
@future(CallOut=true)
public static void getUser(String email)
{
String apiKey = Label.DialpadKey;
String endPoint = 'https://dialpad.com/api/v2/users?email='+email;
Http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setMethod('GET');
request.setHeader('Authorization', 'Bearer '+apiKey);
request.setHeader('Content-Type', 'application/json');
HttpResponse response = http.send(request);
Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> itemList = (List<Object>)responseMap.get('items');
List<Map<String, Object>> allMaps = new List<Map<String, Object>>();
Map<string, List<Object>> finalMap = new Map<string, List<Object>>();
Map<string, List<Object>> forwardingNumbersMap = new Map<string, List<Object>>();
if(itemList == null || itemList.size() == 0)
return;
for(Object obj : itemList){
allMaps.add((Map<String, Object>)obj);
}
for(Map<String, Object> cus : allMaps){
for(string key : cus.keyset()){
if(finalMap.containsKey(key)){
finalMap.get(key).add(cus.get(key));
}else {
List<Object> newObj = new List<Object>();
newObj.add(cus.get(key));
finalMap.put(key,newObj);
}
}
}
String userId = String.ValueOf(finalMap.get('id'));
String finalUserId = '';
if(userId != null && (userId.contains('(') || userId.contains(')')))
{
String removeOpenBrksFromUserId = userId.remove('(');
String removeCloseBrksFromUserId = removeOpenBrksFromUserId.remove(')');
finalUserId = removeCloseBrksFromUserId;
}
SendSMS.sendSMS(finalUserId, new Set<String>{'4013456789'}, 'Customer Name');
}
}
To send SMS from Salesforce, we need to use the API Key generated form the Dialpad in the apex class.
If you want to explore more about Send SMS API in Dialpad, please visit this link: https://developers.dialpad.com/reference/smssend
public class SendSMS {
public static void sendSMS(String userId, Set<String> toNumbersList, String leadName)
{
String apiKey = Label.DialpadKey;
String endPoint = 'https://dialpad.com/api/v2/sms';
String message = 'Hi '+leadName+' I just reached out regarding your property. Sorry I missed you! Feel free to give me a ring anytime, or let me know if there is a next best time for us to connect! I look forward to speaking with you soon! Thanks so much.';
Map<String, Object> mapJson = new Map<String, Object>();
mapJson.put('infer_country_code',false);
mapJson.put('text',message);
mapJson.put('user_id',userId);
mapJson.put('to_numbers',toNumbersList);
String jsonBody = JSON.serialize(mapJson);
Http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setMethod('POST');
request.setHeader('Authorization', 'Bearer '+apiKey);
request.setHeader('Content-Type', 'application/json');
request.setBody(jsonBody);
HttpResponse response = http.send(request);
System.debug('response body: ' +response.getBody());
if(response.getStatusCode() == 200)
System.debug(response.getStatus());
else
{
System.debug(response.getStatusCode());
System.debug(response.getStatus());
}
}
}
After setup all of these, you will able to send the SMS to the customer from Salesforce.
Now we need to call the Send SMS API in the apex class with the API Key.
I hope this blog helped you!