ltdsh/telegram-bot-sender

Simple class for sendinf messages with telegram bot

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/ltdsh/telegram-bot-sender

0.2.2 2023-09-16 21:23 UTC

This package is auto-updated.

Last update: 2025-09-17 01:55:26 UTC


README

Small symfony bundle to send messages via telegram bot

Installation on existing symfony project

composer require ltdsh/telegram-bot-sender

Add bundle to config/bundles.php:

<?php

return [
    ...
    ltdsh\TelegramBotSender\TelegramBotSender::class => ['all' => true],
    ...
];

Configure composer.json in autoload configuration part:

    ...
    "autoload": {
        "psr-4": {
            ...
            "ltdsh\\TelegramBotSender\\": "vendor/ltdsh/telegram-bot-sender/src/"
            ...
        }
    },
    ...

If you want to use bundle as a service, add those lines to config/services.yaml:

services:
    ...
    ltdsh\TelegramBotSender\TelegramBotSender:
        class: ltdsh\TelegramBotSender\TelegramBotSender
    ...

Example(assuming you already have a telegram bot and tg chat with this bot):

class ExampleService
{
    public function __construct(
        private string $telegramBotToken,
        private TelegramBotSender $telegramBotSender
    )
    {
    }
    
    public function sendMessage(): string
    {
        return $this->telegramBotSender
            ->sendSimpleMessage(
                $this->telegramBotToken,
                -123,
                "test message"
            );
    }
}

By the way in this example you also need to configure telegramBotToken variable in services.yaml