Create Slack application
WHATSSUPPPPPPPP GUYS!
✅ Step 1: Create a Slack Incoming Webhook
-
Go to: https://api.slack.com/apps
-
Create a new app or select an existing one.
This part kene manage
-
Go to "Incoming Webhooks" on the left menu.
-
Activate Incoming Webhooks.
-
Click "Add New Webhook to Workspace" and choose the
#pg-alertchannel or any channel that you want. -
Copy the generated Webhook URL (e.g.,
https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXX).
✅ Step 2: Create a Helper or Function in CodeIgniter
You can place this in a helper (application/helpers/slack_helper.php) or directly in a model/controller.
// application/helpers/slack_helper.php
if (!function_exists('send_slack_alert')) {
function send_slack_alert($message)
{
$webhook_url = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXX'; // replace with your URL
$payload = json_encode([
'text' => $message,
'channel' => '#pg-alert', // optional, can be left out if defined in webhook
'username' => 'CI3 Alert',
'icon_emoji' => ':rotating_light:'
]);
$ch = curl_init($webhook_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
if (!function_exists('send_slack_alert')) {
function send_slack_alert($message)
{
$webhook_url = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXX'; // replace with your URL
$payload = json_encode([
'text' => $message,
'channel' => '#pg-alert', // optional, can be left out if defined in webhook
'username' => 'CI3 Alert',
'icon_emoji' => ':rotating_light:'
]);
$ch = curl_init($webhook_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
Huh
ReplyDelete