Last active
October 16, 2023 16:25
-
-
Save FerraBraiZ/391b214e27653f2e4fcd84e386534f82 to your computer and use it in GitHub Desktop.
Slack incoming webhook with php guzzle
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 | |
ini_set('ignore_repeated_errors', 'On'); | |
ini_set('html_errors', 'On'); | |
ini_set('display_errors', 'On'); | |
error_reporting(E_ALL); | |
date_default_timezone_set('America/Sao_Paulo'); | |
// Composer autoloading | |
if (file_exists('vendor/autoload.php')) { | |
require_once('vendor/autoload.php'); | |
} | |
function sendToSlack($text) | |
{ | |
try { | |
$response = (new GuzzleHttp\Client([ | |
'base_uri' => 'https://hooks.slack.com/services/YOUR APP ENDPOINT URI GOES HERE', | |
'headers' => [ | |
'Content-Type' => 'application/json' | |
] | |
]))->request('POST', '', ['json' => [ | |
"text" => GuzzleHttp\json_encode($text) | |
]]); | |
echo \GuzzleHttp\json_decode($response->getBody()->getContents(), true); | |
} catch (\Throwable $e) { | |
echo $e->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment