mirror of
https://github.com/openvk/openvk
synced 2025-02-02 21:15:42 +03:00
Alexander Minkin
6ec54a379d
* feat(lint): add php-cs-fixer for linting Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0. This is not the reformatting commit. * style: format code according to PER-CS 2.0 with php-cs-fixer * ci(actions): add lint action Resolves #1132.
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Util;
|
|
|
|
use GuzzleHttp\Client as GuzzleClient;
|
|
use GuzzleHttp\Exception\ClientException as GuzzleClientException;
|
|
|
|
class Telegram
|
|
{
|
|
public static function send(string $to, string $text, bool $webPagePreview = false): bool
|
|
{
|
|
$conf = (object) OPENVK_ROOT_CONF["openvk"]["credentials"]["telegram"];
|
|
if (!$conf->enable) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
(new GuzzleClient())->request(
|
|
"POST",
|
|
"https://api.telegram.org/bot{$conf->token}/sendMessage",
|
|
[
|
|
"form_params" => [
|
|
"chat_id" => $to,
|
|
"text" => $text,
|
|
"disable_web_page_preview" => $webPagePreview ? "true" : "false",
|
|
"parse_mode" => "HTML",
|
|
],
|
|
]
|
|
);
|
|
} catch (GuzzleClientException $ex) {
|
|
trigger_error("Could not send Telegram message to $to: {$ex->getMessage()}", E_USER_WARNING);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|