ゴジラ

PHP Mattermost incoming hooks

Code,

<?php
function mattermost_send($message) {
        $bot_name="BOT NAME HERE";
        // set post fields
        $post = [
            'payload' => '{"username": "'.$bot_name.'", "text": "'.$message.'"}',
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'API URL HERE');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
        $response = curl_exec($ch);
        var_export($response);
}
?>

To use,

mattermost_send("MESSAGE_HERE");

Last modified: December 06 2019 14:21:55