To configure a webhook in slack is very simple, go to https://yourslack.slack.com/apps/manage/custom-integrations and create a new webhook. Generate the hook and save the url that is required by the script.
Last active
June 26, 2024 17:52
-
-
Save Mte90/f1936c6568c925dec98bacd4a88d53ba to your computer and use it in GitHub Desktop.
Freemius to slack notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get Freemius data | |
$json = file_get_contents('php://input'); | |
$data = json_decode($json, true); | |
if( isset( $data['objects'] ) ) { | |
slack($data); | |
} | |
function slack($data) { | |
$ch = curl_init(); | |
$headers = array( | |
'Accept: application/json', | |
'Content-Type: application/json' | |
); | |
$link = 'https://dashboard.freemius.com/#!/live/plugins/' . $data['objects']['payment']['plugin_id'] . '/users/'. $data['objects']['user_id'] . '/'; | |
$data = array( | |
'text' => 'Sold license :tada: for ' . $data['objects']['payment']['gross'] . '$ to ' . $link, | |
'channel' => 'plugin', //channel | |
'username' => 'freemius-bot', | |
'as_user' => 'true', | |
'link_names' => 'true', | |
'icon_emoji' => ':codeat:' // an emoji as logo | |
); | |
curl_setopt($ch, CURLOPT_URL, 'you slack webhhok url'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$result = curl_exec($ch); | |
if (curl_errno($ch)) { | |
error_log( 'Error:' . curl_error($ch) ); | |
} | |
curl_close ($ch); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment