<commit_before><?php

namespace SlackBot;

/**
 * Class SlackBotEngine
 * @package SlackBot
 */
class SlackBotEngine
{
    const END_POINT = 'https://slack.com/api/chat.postMessage';
    const API_TOKEN = 'YOUR_API_TOKEN';
    const CHANNEL_NAME = '#general';
    const BOT_USERNAME = 'YOUR_BOT_USERNAME';
    const OUTGOING_WEBHOOK_TOKEN = 'YOUR_OUTGOING_WEBHOOK_TOKEN';
    const CHAT_LOGGING = true;
    const CHAT_LOGGING_FILE_NAME = 'chat_log.txt';

    private $receivedData;

    /**
     * SlackBotEngine constructor.
     */
    public function __construct()
    {
        $this->receivedData = $_POST;

        if ($this->verifyRequest() !== true) {
            throw new \Exception('Request is not valid');
        }
    }

    /**
     * Listen to incoming requests from Slack
     */
    public function listen()
    {
        $this->logChat($this->receivedData['text'], __METHOD__);

        $this->send('Your message received');
        // Body goes here
    }

    /**
     * @param $message
     *
     * @return bool|mixed
     */
    public function send($message)
    {
        if ($this->isThisBot()) {
            return false;
        }

        $ch = curl_init(self::END_POINT);
        $data = http_build_query([
            "token" => self::API_TOKEN,
            "channel" => self::CHANNEL_NAME,
            "text" => $message,
            "username" => self::BOT_USERNAME,
        ]);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        curl_close($ch);

        $this->logChat($message, __METHOD__);

        return $result;
    }

    /**
     * @return bool
     */
    private function isThisBot()
    {
        if ((isset($this->receivedData['user_id']) && $this->receivedData['user_id'] == 'USLACKBOT')
        || (isset($this->receivedData['user_name']) && $this->receivedData['user_name'] == 'slackbot')) {<commit_msg>Add as_user and icon_url parameter<commit_after><?php

namespace SlackBot;

/**
 * Class SlackBotEngine
 * @package SlackBot
 */
class SlackBotEngine
{
    const END_POINT = 'https://slack.com/api/chat.postMessage';
    const API_TOKEN = 'YOUR_API_TOKEN';
    const CHANNEL_NAME = '#general';
    const BOT_USERNAME = 'YOUR_BOT_USERNAME';
    const OUTGOING_WEBHOOK_TOKEN = 'YOUR_OUTGOING_WEBHOOK_TOKEN';
    const CHAT_LOGGING = true;
    const CHAT_LOGGING_FILE_NAME = 'chat_log.txt';
    const ICON_URL = 'YOUR_BOT_ICON_URL_48_BY_48';

    private $receivedData;

    /**
     * SlackBotEngine constructor.
     */
    public function __construct()
    {
        $this->receivedData = $_POST;

        if ($this->verifyRequest() !== true) {
            throw new \Exception('Request is not valid');
        }
    }

    /**
     * Listen to incoming requests from Slack
     */
    public function listen()
    {
        $this->logChat($this->receivedData['text'], __METHOD__);

        $this->send('Your message received');
        // Body goes here
    }

    /**
     * @param $message
     *
     * @return bool|mixed
     */
    public function send($message)
    {
        if ($this->isThisBot()) {
            return false;
        }

        $ch = curl_init(self::END_POINT);
        $data = http_build_query([
            'token' => self::API_TOKEN,
            'channel' => self::CHANNEL_NAME,
            'text' => $message,
            'username' => self::BOT_USERNAME,
            'as_user' => false,
            'icon_url' => self::ICON_URL
        ]);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        curl_close($ch);

        $this->logChat($message, __METHOD__);

        return $result;
    }

    /**
     * @return bool
     */
    private function isThisBot()
    {
        if ((isset($this->receivedData['user_id']) && $this->receivedData['user_id'] == 'USLACKBOT')
        || (isset($this->receivedData['user_name']) && $this->receivedData['user_name'] == 'slackbot')) {
{'fraction_non_alphanumeric': 0.14319084326092035, 'fraction_numerical': 0.000934361130576968, 'mean_word_length': 2.433841218925421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3554210', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1370, 'n_words': 249}