Created
September 27, 2016 17:50
-
-
Save pascalwacker/4a85a04e844fa72f59626eb3fea5c0f7 to your computer and use it in GitHub Desktop.
Mattermost PHP Post example
This file contains hidden or 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
// target webhook | |
$target = 'https://dev.bermos.tech/hooks/xxx'; // get your webhook at "Integrationen" at the settings | |
// message body | |
$body = "| Course | Time | Room | Video | Prof |\n"; | |
$body .= "|:--|:--|:--|\n"; | |
$body .= "| Test | XX:XX-YY:YY | HG E7 | :white_check_mark: HG E5 | FooBar |\n"; | |
$body .= "| Test 2 | XX:XX-YY:YY | HG E7 | No | FooBar |\n"; | |
$body .= "\n"; | |
// this is an example for a course bot, using a table. Mattermost supports MD | |
// https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet | |
// payload construction | |
$payload = 'payload={"text": "'; | |
$payload .= str_replace('"', '\"', $body); | |
$payload .= '"}'; | |
// init cURL | |
$ch = curl_init(); | |
// set cURL options | |
curl_setopt($ch, CURLOPT_URL, $target); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
// enable return and execute | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$server_output = curl_exec ($ch); | |
// close connection | |
curl_close($ch); | |
// check if the request was processed | |
if ($server_output == 'ok') { | |
var_dump('yayy every thing works!'); | |
} else { | |
var_dump('shit! something is broken...'); | |
} | |
// output return of the server | |
var_dump($server_output); | |
// output target url and sen't payload | |
var_dump($target, $payload); | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment