amrs-tech / Hacktoberfest-Beginner-level

A beginner-friendly repository to help first-time-contributors in the open source.
MIT License
45 stars 185 forks source link

Create Salesforce #253

Closed olipoligo closed 4 years ago

olipoligo commented 4 years ago

Apex class definitions

olipoligo commented 4 years ago

/* Sample callout to Plivo service that will automatically call Leads. This is part of a broader framework that will be published soon. MCP == The phone# associated with a call center or business phone phone == the number to be dialed.

*/

public class Plivo_Callout {

@future(callout = true)
public static void call(String mcp, String phone){

//Config object for callout

        String authToken = config.twilio_AuthToken__c;

        HttpRequest req = new HttpRequest();
        Http http = new Http();
        HttpResponse resp = new HttpResponse();

        Blob headerValue = Blob.valueOf(authToken);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);

        req.setEndpoint('https://api.plivo.com/v1/Account/your key here/Call/');
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type', 'application/json');
        req.setBody(
                    '{"to":"' + mcp + '",'  
                    +'"from":"' + phone + '",'
                    +'"answer_url":"' + config.answer_url__c  + phone + '",'
                    +'"answer_method":"POST"}' 
                    );    

         req.setTimeout(20000); 
         req.setMethod('POST');

         System.debug('request:' + req.getBody());
         System.debug('header:' + req);

         if(!Test.isRunningTest()){

                resp = http.send(req);
         }

     System.debug('response:' + resp);     
     System.debug('response body:' + resp.getBody());

}

}