kavalar/telegram_bot

Telegram Bot Service

0.2 2021-08-25 14:10 UTC

This package is auto-updated.

Last update: 2024-04-25 20:11:23 UTC


README

Telegram Bot Service

TelegramBotService

Methods

sendMessageTo($chat_id, $message)

Use this method to send message to given chat.

$bot = new TelegramBotService($token);
$result = $bot->sendMessageTo($chat_id, $message);

BotNotificationTemplateProcessor

Methods

__construct($templates)

$templates is associative array such format

[
   'template_name' => "Hello ~name~"
];

Where ~name~ is parameter which could be rendered by renderTemplate method

renderTemplate($template_name, $parameters)

Returns rendered template

$args is associative array such format

[
   'name' => 'Jhon'
];

Throws NoSuchParameterException, NoSuchTemplateException,

Example

$bot = new TelegramBotService($token);

$templates = [
    'example' => "Hello ~name~"
];
$attributes = [
    'name' => 'Jhon'
];

$templateProcessor = new BotNotificationTemplateProcessor($templates);
$message = $templateProcessor->renderTemplate('example', $attributes);

$result = $bot->sendMessageTo($chat_id, $message);

Watch full example at example.php