{"id":18542084,"url":"https://github.com/luzrain/telegram-bot-bundle","last_synced_at":"2025-04-09T18:31:26.817Z","repository":{"id":176740601,"uuid":"656659312","full_name":"luzrain/telegram-bot-bundle","owner":"luzrain","description":"Symfony bundle for Telegram Bot API","archived":false,"fork":false,"pushed_at":"2025-03-18T16:30:54.000Z","size":100,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:36:51.016Z","etag":null,"topics":["telegram","telegram-bot","telegram-bot-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luzrain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-21T11:31:21.000Z","updated_at":"2025-03-18T16:28:17.000Z","dependencies_parsed_at":"2023-07-10T21:30:31.843Z","dependency_job_id":"49d56c66-5cc2-431d-b9a8-9d9b2a036208","html_url":"https://github.com/luzrain/telegram-bot-bundle","commit_stats":null,"previous_names":["luzrain/telegram-bot-bundle"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Ftelegram-bot-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Ftelegram-bot-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Ftelegram-bot-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Ftelegram-bot-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luzrain","download_url":"https://codeload.github.com/luzrain/telegram-bot-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248087738,"owners_count":21045579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["telegram","telegram-bot","telegram-bot-bundle"],"created_at":"2024-11-06T20:07:13.737Z","updated_at":"2025-04-09T18:31:21.799Z","avatar_url":"https://github.com/luzrain.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony bundle for Telegram Bot API\n[![PHP \u003e=8.2](https://img.shields.io/badge/PHP-\u003e=8.2-777bb3.svg?style=flat)](https://www.php.net/releases/8.2/en.php)\n![Symfony ^7.0](https://img.shields.io/badge/Symfony-^7.0-374151.svg?style=flat)\n[![Tests Status](https://img.shields.io/github/actions/workflow/status/luzrain/telegram-bot-bundle/tests.yaml?branch=master)](../../actions/workflows/tests.yaml)\n\nA symfony bundle for [luzrain/telegram-bot-api](https://github.com/luzrain/telegram-bot-api) library.\n\n## Getting started\n### Install composer packages\n```bash\n$ composer require luzrain/telegram-bot-bundle symfony/http-client nyholm/psr7\n```\n\n### Enable the Bundle\n```php\n\u003c?php\n// config/bundles.php\n\nreturn [\n    // ...\n    Luzrain\\TelegramBotBundle\\TelegramBotBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n### Configure bundle\n```yaml\n# config/packages/telegram_bot.yaml\n\ntelegram_bot:\n  api_token: API_TOKEN\n#  webhook:\n#    url: https://localhost/tg-webhook\n```\n\n### Optional. Configure webhook route\n```yaml\n# config/routes.yaml\n\n# ...\ntelegram_webhook:\n  path: /tg-webhook\n  controller: telegram_bot.webhook_controller\n```\n\nNote that *symfony/http-client* and *nyholm/psr7* are not necessary. You can use any PSR-18 client and PSR-17 factories.  \nSet custom services in *http_client*, *request_factory*, *stream_factory* options in *telegram_bot.yaml* configuration file.  \nHere is an example how to use [guzzle](https://github.com/guzzle/guzzle) http client:\n\n```yaml\n# config/services.yaml\n\npsr18.guzzle_client:\n  class: GuzzleHttp\\Client\n  arguments:\n    - http_errors: false\n\npsr17.guzzle_factory:\n  class: GuzzleHttp\\Psr7\\HttpFactory\n```\n\n```yaml\n# config/packages/telegram_bot.yaml\n\ntelegram_bot:\n  http_client: psr18.guzzle_client\n  request_factory: psr17.guzzle_factory\n  stream_factory: psr17.guzzle_factory\n  api_token: API_TOKEN\n```\n\nFor a complete list of available options with documentation, see the command output.\n```bash\n$ bin/console config:dump-reference telegram_bot\n```\n\n### Getting messages from telegram\nThere are two ways to receive messages from Telegram.\n#### Webhook. Recommended way.\nYou must configure the webhook route and make it available from the Internet.  \nConfigure *webhook.url* option in *telegram_bot.yaml* configuration file;  \nUpdate the webhook configuration in telegram bot with the command.  \n```bash\n$ bin/console telegram:webhook:update\n```\n\nNote that each time you change *webhook* and *allowed_updates* options in configuration files you should run this command for update telegram bot settings.\n\n#### Polling daemon.  \nUse it in a development environment or if you can't provide public access to the webhook url.  \nRun the polling daemon with the command.  \n```bash\n$ bin/console telegram:polling:start\n```\n\n## Examples\n### Command controller\n```php\nuse Luzrain\\TelegramBotApi\\Method;\nuse Luzrain\\TelegramBotApi\\Type;\nuse Luzrain\\TelegramBotBundle\\Attribute\\OnCommand;\nuse Luzrain\\TelegramBotBundle\\TelegramCommand;\n\nfinal class StartCommandController extends TelegramCommand\n{\n    // You can pass command arguments next to $message.\n    // Be aware to set default values for arguments as they won't necessarily will be passed\n    #[OnCommand('/start')]\n    public function __invoke(Type\\Message $message, string $arg1 = '', string $arg2 = ''): Method\n    {\n        return $this-\u003ereply('Hello from symfony bot');\n    }\n}\n```\n\n### Any event controller\n```php\nuse Luzrain\\TelegramBotApi\\Event;\nuse Luzrain\\TelegramBotApi\\Method;\nuse Luzrain\\TelegramBotApi\\Type;\nuse Luzrain\\TelegramBotBundle\\Attribute\\OnEvent;\n\n// It's not necessary to extend TelegramCommand\nfinal class OnMessageController\n{\n    // Listen any available event from Event namespace\n    #[OnEvent(Event\\Message::class)]\n    public function __invoke(Type\\Message $message): Method\n    {\n        return new Method\\SendMessage(\n            chatId: $message-\u003echat-\u003eid,\n            text: 'You wrote: ' . $message-\u003etext,\n        );\n    }\n}\n```\n\n### Publish command list as bot button\nIt's possible to publish all your commands, which will be shown as a list of available commands in the bot's menu button.\nTo do this, fill in the *description* field and the *publish* flag in the OnCommand attribute.\n```php\n#[OnCommand(command: '/command1', description: 'Test command 1', publish: true)]\n```\n\nRun the command for publish.\n```bash\n$ bin/console telegram:button:update\n```\n\nFor button delete.\n```bash\n$ bin/console telegram:button:delete\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluzrain%2Ftelegram-bot-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluzrain%2Ftelegram-bot-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluzrain%2Ftelegram-bot-bundle/lists"}