Last active
October 23, 2015 19:05
-
-
Save finferflu/e513ac90b18ebbd3cc10 to your computer and use it in GitHub Desktop.
Sample POST to Slack API method chat.postMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$payload = array( | |
'token' => 'xxxx-xxxxxxxxx-xxxx', | |
'channel => 'C1234567890', | |
'attachments' => array(array( | |
'text' => "This is my post body", | |
'fallback' => "This is the fallback" | |
))); | |
$data_str = json_encode($payload); | |
curl_setopt($ch, CURLOPT_URL, 'https://slack.com/api/chat.postMessage'); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($data_str)) | |
); | |
$res = curl_exec($ch); | |
print_r($res); | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment