private function send($message)
    {
        $url = self::BASE_URI . $this->token . '/sendMessage';
        $data = [
            'chat_id'                  => $this->chatId,
            'text'                     => $message,
            'disable_web_page_preview' => true // Just in case there is a link in the message
        ];

        // Set HTML parse mode when HTML code is detected
        if (preg_match('/<[^<]+>/', $data['text']) !== false) {
            $data['parse_mode'] = 'HTML';
        }

        if ($this->useCurl === true && extension_loaded('curl')) {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
            curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);

            $result = curl_exec($ch);
            if (!$result) {
                throw new \RuntimeException('Request to Telegram API failed: ' . curl_error($ch));
            }
        } else {
            $opts = [
                'http' => [
                    'method'  => 'POST',
                    'header'  => 'Content-type: application/x-www-form-urlencoded',
                    'content' => http_build_query($data),
                    'timeout' => $this->timeout,
                ],
                'ssl'  => [
                    'verify_peer'      => $this->verifyPeer,
                    'verify_peer_name' => $this->verifyPeer,
                ],
            ];

            $result = @file_get_contents($url, false, stream_context_create($opts));
            if (!$result) {
                $error = error_get_last();
                if (isset($error['message'])) {
                    throw new \RuntimeException('Request to Telegram API failed: ' . $error['message']);
                }

                throw new \RuntimeException('Request to Telegram API failed');
            }
        }

        $result = json_decode($result, true);
        if (isset($result['ok']) && $result['ok'] === true) {
            return true;
        }

        if (isset($result['description'])) {
            throw new \RuntimeException('Telegram API error: ' . $result['description']);
        }

        return false;
    }
private function send($message)
    {
        $url = self::BASE_URI . $this->token . '/sendMessage';
        $data = [
            'chat_id'                  => $this->chatId,
            'text'                     => $message,
            'disable_web_page_preview' => true // Just in case there is a link in the message
        ];

        // Set HTML parse mode when HTML code is detected
        if (preg_match('/<[^<]+>/', $data['text']) !== false) {
            $data['parse_mode'] = 'HTML';
        }

        if ($this->useCurl === true && extension_loaded('curl')) {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
            curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);

            $result = curl_exec($ch);
            if (!$result) {
                throw new \RuntimeException('Request to Telegram API failed: ' . curl_error($ch));
            }
        } else {
            $opts = [
                'http' => [
                    'method'  => 'POST',
                    'header'  => 'Content-type: application/x-www-form-urlencoded',
                    'content' => http_build_query($data),
                    'timeout' => $this->timeout,
                ],
                'ssl'  => [
                    'verify_peer'      => $this->verifyPeer,
                    'verify_peer_name' => $this->verifyPeer,
                ],
            ];

            $result = @file_get_contents($url, false, stream_context_create($opts));
            if (!$result) {
                $error = error_get_last();
                if (isset($error['message'])) {
                    throw new \RuntimeException('Request to Telegram API failed: ' . $error['message']);
                }

                throw new \RuntimeException('Request to Telegram API failed');
            }
        }

        $result = json_decode($result, true);
        if (isset($result['ok']) && $result['ok'] === true) {
            return true;
        }

        if (isset($result['description'])) {
            throw new \RuntimeException('Telegram API error: ' . $result['description']);
        }

        return false;
    }
private function send ( $ message ) { $ url = self :: BASE_URI . $ this -> token . '/sendMessage' ; $ data = [ 'chat_id' => $ this -> chatId , 'text' => $ message , 'disable_web_page_preview' => true // Just in case there is a link in the message ] ; // Set HTML parse mode when HTML code is detected if ( preg_match ( '/<[^<]+>/' , $ data [ 'text' ] ) !== false ) { $ data [ 'parse_mode' ] = 'HTML' ; } if ( $ this -> useCurl === true && extension_loaded ( 'curl' ) ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , http_build_query ( $ data ) ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , $ this -> verifyPeer ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , $ this -> timeout ) ; $ result = curl_exec ( $ ch ) ; if ( ! $ result ) { throw new \ RuntimeException ( 'Request to Telegram API failed: ' . curl_error ( $ ch ) ) ; } } else { $ opts = [ 'http' => [ 'method' => 'POST' , 'header' => 'Content-type: application/x-www-form-urlencoded' , 'content' => http_build_query ( $ data ) , 'timeout' => $ this -> timeout , ] , 'ssl' => [ 'verify_peer' => $ this -> verifyPeer , 'verify_peer_name' => $ this -> verifyPeer , ] , ] ; $ result = @ file_get_contents ( $ url , false , stream_context_create ( $ opts ) ) ; if ( ! $ result ) { $ error = error_get_last ( ) ; if ( isset ( $ error [ 'message' ] ) ) { throw new \ RuntimeException ( 'Request to Telegram API failed: ' . $ error [ 'message' ] ) ; } throw new \ RuntimeException ( 'Request to Telegram API failed' ) ; } } $ result = json_decode ( $ result , true ) ; if ( isset ( $ result [ 'ok' ] ) && $ result [ 'ok' ] === true ) { return true ; } if ( isset ( $ result [ 'description' ] ) ) { throw new \ RuntimeException ( 'Telegram API error: ' . $ result [ 'description' ] ) ; } return false ; }
Send sendMessage request to Telegram Bot API

@param string $message The message to send

@return bool
Send sendMessage request to Telegram Bot API