Skip to content

Instantly share code, notes, and snippets.

@abcprintf
Created May 3, 2019 03:17
Show Gist options
  • Save abcprintf/25ecfe6217f73bf9eda67c7f8e092630 to your computer and use it in GitHub Desktop.
Save abcprintf/25ecfe6217f73bf9eda67c7f8e092630 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
// Attachments Form :
// $data = array(
// 'attachments' => array(
// 0 => array(
// 'fallback' => 'Required plain-text summary of the attachment.',
// 'color' => '#36a64f',
// 'pretext' => 'Optional text that appears above the attachment block',
// 'author_name' => 'Bobby Tables',
// 'author_link' => 'http://flickr.com/bobby/',
// 'author_icon' => 'http://flickr.com/icons/bobby.jpg',
// 'title' => 'Slack API Documentation',
// 'title_link' => 'https://api.slack.com/',
// 'text' => 'Optional text that appears within the attachment',
// 'fields' => array(
// 0 => array(
// 'title' => 'Priority',
// 'value' => 'High',
// 'short' => false,
// ),
// ),
// 'image_url' => 'http://my-website.com/path/to/image.jpg',
// 'thumb_url' => 'http://example.com/path/to/thumb.png',
// 'footer' => 'Slack API',
// 'footer_icon' => 'https://platform.slack-edge.com/img/default_application_icon.png',
// 'ts' => 123456789,
// ),
// ),
// );
// Message buttons Form :
// $data = array(
// 'text' => 'Would you like to play a game?',
// 'attachments' => array(
// 0 => array(
// 'text' => 'Choose a game to play',
// 'fallback' => 'You are unable to choose a game',
// 'callback_id' => 'wopr_game',
// 'color' => '#3AA3E3',
// 'attachment_type' => 'default',
// 'actions' => array(
// 0 => array(
// 'name' => 'game',
// 'text' => 'Chess',
// 'type' => 'button',
// 'value' => 'chess',
// ),
// 1 => array(
// 'name' => 'game',
// 'text' => 'Falken\'s Maze',
// 'type' => 'button',
// 'value' => 'maze',
// ),
// 2 => array(
// 'name' => 'game',
// 'text' => 'Thermonuclear War',
// 'style' => 'danger',
// 'type' => 'button',
// 'value' => 'war',
// 'confirm' => array(
// 'title' => 'Are you sure?',
// 'text' => 'Wouldn\'t you prefer a good game of chess?',
// 'ok_text' => 'Yes',
// 'dismiss_text' => 'No',
// ),
// ),
// ),
// ),
// ),
// );
// Basic formatting Form :
$data = array(
'text' => 'This is a line of text. And this is another one.',
);
$json_string = json_encode($data);
// Your webhook URL
$webhook_url = '';
$slack_call = curl_init();
curl_setopt($slack_call, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($slack_call, CURLOPT_POSTFIELDS, $json_string);
curl_setopt($slack_call, CURLOPT_CRLF, true);
curl_setopt($slack_call, CURLOPT_RETURNTRANSFER, true);
curl_setopt($slack_call, CURLOPT_URL, $webhook_url);
curl_setopt($slack_call, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($slack_call, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Content-Length:' . strlen($json_string))
);
$result = curl_exec($slack_call);
curl_close($slack_call);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment