<?php

namespace Eesa\CoreBundle\Manager;

class SlackManager
{
    public function __construct()
    {
        $this->hookUrl = 'https://hooks.slack.com/services/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';
    }

    public function sendMessage($message, $salon = '#santander', $username = 'Babouche')
    {
        //$message = '{"channel": "#santander", "username": "Fantôme", "text": "' . $message . '", "icon_emoji": ":ghost:"}';
        $data = array(
            'channel'       => $salon,
            'username'      => $username,
            'text'          => $message,
            'icon_emoji'    => ':monkey:'
        );
        $json = json_encode($data);

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, $this->hookUrl);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($json))
        );
        curl_exec($ch);
        curl_close($ch);
    }
}