Create Slack application

 WHATSSUPPPPPPPP GUYS!


✅ Step 1: Create a Slack Incoming Webhook

  1. Go to: https://api.slack.com/apps

  2. Create a new app or select an existing one.


This part kene manage 

  1. Go to "Incoming Webhooks" on the left menu.

  2. Activate Incoming Webhooks.

  3. Click "Add New Webhook to Workspace" and choose the #pg-alert channel or any channel that you want.

  4. 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;
    }
}





Comments

Post a Comment

Popular posts from this blog

Tips testing local untuk programmer 📌

Get list of controller in Codeigniter