Skip to content

Instantly share code, notes, and snippets.

@stefanzweifel
Created May 8, 2014 13:26
Show Gist options
  • Select an option

  • Save stefanzweifel/04be27486517cd7d3422 to your computer and use it in GitHub Desktop.

Select an option

Save stefanzweifel/04be27486517cd7d3422 to your computer and use it in GitHub Desktop.
Slack.com Webhook Integration (PHP) - Simple snippet which tells you, how to build your payload array.
<?php
//Options
$token = 'YOUR_TOKEN_HERE';
$domain = 'YOUR_SLACK_DOMAIN_GOES_HERE';
$channel = '#general';
$bot_name = 'Webhook';
$icon = ':alien:';
$message = 'Your message';
$attachments = array([
'fallback' => 'Lorem ipsum',
'pretext' => 'Lorem ipsum',
'color' => '#ff6600',
'fields' => array(
[
'title' => 'Title',
'value' => 'Lorem ipsum',
'short' => true
],
[
'title' => 'Notes',
'value' => 'Lorem ipsum',
'short' => true
]
)
]);
$data = array(
'channel' => $channel,
'username' => $bot_name,
'text' => $message,
'icon_emoji' => $icon,
'attachments' => $attachments
);
$data_string = json_encode($data);
$ch = curl_init('https://'.$domain.'.slack.com/services/hooks/incoming-webhook?token='.$token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
//Execute CURL
$result = curl_exec($ch);
return $result;
?>
@theresajamesumasino
Copy link
Copy Markdown

omg thanks!

@theresajamesumasino
Copy link
Copy Markdown

is this laravel?

@1000heads-luke
Copy link
Copy Markdown

is this laravel?

No. This is normal PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment