Skip to content

Instantly share code, notes, and snippets.

@FerraBraiZ
Last active October 16, 2023 16:25
Show Gist options
  • Save FerraBraiZ/391b214e27653f2e4fcd84e386534f82 to your computer and use it in GitHub Desktop.
Save FerraBraiZ/391b214e27653f2e4fcd84e386534f82 to your computer and use it in GitHub Desktop.
Slack incoming webhook with php guzzle
<?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