Skip to content

Instantly share code, notes, and snippets.

@ianthekid
Last active December 16, 2020 00:03
Show Gist options
  • Save ianthekid/cc363eadd3031b32b3b0227041934f84 to your computer and use it in GitHub Desktop.
Save ianthekid/cc363eadd3031b32b3b0227041934f84 to your computer and use it in GitHub Desktop.
<?php
function sendToSlack($lead, $sfdcId, $channel) {
$slack = [
"text" => '',
"username" => $lead['firstName']." ".$lead['lastName'],
"icon_emoji" => ':fire:',
"attachments" => [[
"color" => '#FA9100',
"title" => 'Open in Salesforce »',
"title_link" => "https://salesforce.com/r/Lead/".$sfdcId."/view",
"fields" => [
[ "title" => 'Company', "value" => $lead['company'], "short" => "true" ],
[ "title" => 'Email', "value" => $lead['email'], "short" => "true" ],
[ "title" => 'Phone', "value" => $lead['phone'], "short" => "true" ],
[ "title" => 'Web Form', "value" => $lead['form'], "short" => "true" ],
[ "title" => 'Source', "value" => $lead['source'], "short" => "true" ],
[ "title" => 'Referrer', "value" => $lead['referrer'], "short" => "true" ],
[ "title" => 'AE Meeting Status', "value" => 'None', "short" => "true" ],
[ "title" => 'SFDC Record Type', "value" => 'Lead', "short" => "true" ],
],
]],
];
$ch = curl_init();
$options = array(
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_URL => $channel,
CURLOPT_REFERER => "canto.com",
CURLOPT_USERAGENT => "Canto Website",
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 60,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($slack),
);
curl_setopt_array( $ch, $options );
$response = curl_exec( $ch );
return $response;
}
$lead = array(
'firstName' => 'Bugs',
'lastName' => 'Bunny',
'company' => 'Looney Tunes',
'email' => '[email protected]',
'phone' => '(123) 456-7890',
'form' => 'Free Trial',
'source' => 'Search Paid',
'referrer' => 'Google'
);
$sfdcId = 'abc123';
$url = 'https://webhook.site/bd2be8d3-0aa3-4bbb-9e13-38c21187843c';
sendToSlack($lead, $sfdcId, $url);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment