openvk/Web/Util/Telegram.php
Alexander Minkin 6ec54a379d
feat: add linting of code (#1220)
* 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.
2025-01-31 18:20:13 +03:00

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;
}
}