{"id":15063326,"url":"https://github.com/boshurik/telegrambotbundle","last_synced_at":"2025-04-07T13:10:25.906Z","repository":{"id":7978972,"uuid":"57029779","full_name":"BoShurik/TelegramBotBundle","owner":"BoShurik","description":"Symfony Telegram Bot Bundle","archived":false,"fork":false,"pushed_at":"2023-12-22T12:47:43.000Z","size":195,"stargazers_count":66,"open_issues_count":1,"forks_count":22,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T05:02:48.063Z","etag":null,"topics":["php","symfony","symfony-bundle","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/BoShurik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-04-25T09:35:31.000Z","updated_at":"2024-06-19T03:55:53.284Z","dependencies_parsed_at":"2022-08-21T09:20:29.664Z","dependency_job_id":"8aa4d1c2-0c9e-4718-b7d8-e645bfc5356e","html_url":"https://github.com/BoShurik/TelegramBotBundle","commit_stats":{"total_commits":106,"total_committers":6,"mean_commits":"17.666666666666668","dds":0.1132075471698113,"last_synced_commit":"03d2acf9641ee457974a19f46f8216ae8f087c18"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoShurik%2FTelegramBotBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoShurik%2FTelegramBotBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoShurik%2FTelegramBotBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoShurik%2FTelegramBotBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoShurik","download_url":"https://codeload.github.com/BoShurik/TelegramBotBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657282,"owners_count":20974345,"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":["php","symfony","symfony-bundle","telegram","telegram-bot","telegram-bot-bundle"],"created_at":"2024-09-24T23:55:01.183Z","updated_at":"2025-04-07T13:10:25.866Z","avatar_url":"https://github.com/BoShurik.png","language":"PHP","readme":"# TelegramBotBundle\n\nTelegram bot bundle on top of [`telegram-bot/api`][1] library\n\n## Examples\n\nSee [example project][5]\n\n## Installation\n\n#### Composer\n\n``` bash\n$ composer require boshurik/telegram-bot-bundle\n```\n\nIf you are using [symfony/flex][6] all you need is to set `TELEGRAM_BOT_TOKEN` environment variable\n\n#### Register the bundle\n\n``` php\n\u003c?php\n// app/AppKernel.php\n\npublic function registerBundles()\n{\n    $bundles = array(\n        // ...\n        new BoShurik\\TelegramBotBundle\\BoShurikTelegramBotBundle,\n    );\n    // ...\n}\n```\n\n#### Add routing for webhook\n\n``` yaml\nBoShurikTelegramBotBundle:\n    resource: \"@BoShurikTelegramBotBundle/Resources/config/routing.php\"\n    prefix: /_telegram/%telegram_bot_route_secret%\n```\n\nor for multiple bots:\n``` yaml\nBoShurikTelegramBotBundle:\n    resource: \"@BoShurikTelegramBotBundle/Resources/config/routing.php\"\n    prefix: /_telegram/{bot}/%telegram_bot_route_secret%\n```\n\n#### Configuration\n\n``` yaml\nboshurik_telegram_bot:\n    api:\n        token: \"%telegram_bot_api_token%\"\n        proxy: \"socks5://127.0.0.1:8888\"\n```\n\nor for multiple bots:\n``` yaml\nboshurik_telegram_bot:\n    api:\n        default_bot: first\n        bots:\n            first: \"%first_telegram_bot_api_token%\"\n            second: \"%second_telegram_bot_api_token%\"\n        proxy: \"socks5://127.0.0.1:8888\"\n```\n\n## Usage\n\n#### API\n\nTo get default bot api:\n```php\nuse TelegramBot\\Api\\BotApi;\npublic function __construct(private BotApi $api)\n```\n\nFor multiple bots:\n\n```php\n\nuse BoShurik\\TelegramBotBundle\\Telegram\\BotLocator;\nuse TelegramBot\\Api\\BotApi;\n\npublic function foo(BotLocator $botLocator)\n{\n    /** @var BotApi $api */\n    $api = $botLocator-\u003eget('first');\n}\n```\nor use argument with type `TelegramBot\\Api\\BotApi` and name pattern `/\\${name}(Bot|BotApi|Api)?$/`\n```php\nuse TelegramBot\\Api\\BotApi;\npublic function __construct(private BotApi $firstBotApi)\n```\n\nFor more info see [Usage][2] section in [`telegram-bot/api`][1] library\n\n#### Getting updates\n\n``` bash\nbin/console telegram:updates\nbin/console telegram:updates first\n```\n\nFor more information see [official documentation][3]\n\n#### Webhook\n\n##### Set\n\n``` bash\nbin/console telegram:webhook:set [url-or-hostname] [\u003cpath-to-certificate\u003e]\nbin/console telegram:webhook:set [url-or-hostname] [\u003cpath-to-certificate\u003e] --bot first\n```\n\nIf `url-or-hostname` is not set command will generate url based on [request context](https://symfony.com/doc/current/routing.html#generating-urls-in-commands)\n\n##### Unset\n\n``` bash\nbin/console telegram:webhook:unset\nbin/console telegram:webhook:unset first\n```\n\nFor more information see [official documentation][4]\n\n#### Async command processing\n\nTo improve performance, you can leverage [Messenger][7] to process webhooks later via a Messenger transport.\n\n```bash\ncomposer req symfony/messenger\n```\n\n```yaml\n# config/packages/messenger.yaml\nframework:\n    messenger:\n        transports:\n            async: \"%env(MESSENGER_TRANSPORT_DSN)%\"\n\n        routing:\n            'BoShurik\\TelegramBotBundle\\Messenger\\TelegramMessage': async\n```\n\n#### Adding commands\n\nCommands must implement `\\BoShurik\\TelegramBotBundle\\Telegram\\Command\\CommandInterface`\n\nThere is `\\BoShurik\\TelegramBotBundle\\Telegram\\Command\\AbstractCommand` you can start with\n\nTo register command: add tag `boshurik_telegram_bot.command` to service definition\n``` yaml\napp.telegram.command:\n    class: AppBundle\\Telegram\\Command\\SomeCommand\n    tags:\n        - { name: boshurik_telegram_bot.command }\n```\n\nIf you use `autoconfigure` tag will be added automatically\n\nFor application with multiple bots you need to pass bot id:\n``` yaml\napp.telegram.command:\n    class: AppBundle\\Telegram\\Command\\SomeCommand\n    tags:\n        - { name: boshurik_telegram_bot.command, bot: first }\n```\nIf you need to use same command for multiple bots you must add multiple tags for each bot:\n``` yaml\napp.telegram.command:\n    class: AppBundle\\Telegram\\Command\\SomeCommand\n    tags:\n        - { name: boshurik_telegram_bot.command, bot: first }\n        - { name: boshurik_telegram_bot.command, bot: second }\n```\n\nThere is predefined `\\BoShurik\\TelegramBotBundle\\Telegram\\Command\\HelpCommand`.\nIt displays commands which additionally implement `\\BoShurik\\TelegramBotBundle\\Telegram\\Command\\PublicCommandInterface`\n\nYou need to register it:\n``` yaml\napp.telegram.command.help:\n    class: BoShurik\\TelegramBotBundle\\Telegram\\Command\\HelpCommand\n    arguments:\n        - '@boshurik_telegram_bot.command.registry.default'\n    tags:\n        - { name: boshurik_telegram_bot.command }\n```\nor for multiple bots:\n``` yaml\napp.telegram.command.help:\n    class: BoShurik\\TelegramBotBundle\\Telegram\\Command\\HelpCommand\n    arguments:\n        - '@boshurik_telegram_bot.command.registry.first'\n    tags:\n        - { name: boshurik_telegram_bot.command, bot: first }\n```\n\n#### Events\n\nFor more complex application (e.g. conversations) you can listen for `BoShurik\\TelegramBotBundle\\Event\\UpdateEvent` event\n``` php\n/**\n * @param UpdateEvent $event\n */\npublic function onUpdate(UpdateEvent $event)\n{\n    $update = $event-\u003egetUpdate();\n    $message = $update-\u003egetMessage();\n}\n```\n\n## Login with Telegram\n\nThis bundle supports login through Telegram Api\n\nIf you want to allow your Bot's users to login without requiring them to register again\nfollow these [instructions](LOGIN_WITH_TELEGRAM.md).\n\n[1]: https://github.com/TelegramBot/Api\n[2]: https://github.com/TelegramBot/Api#usage\n[3]: https://core.telegram.org/bots/api#getupdates\n[4]: https://core.telegram.org/bots/api#setwebhook\n[5]: https://github.com/BoShurik/telegram-bot-example\n[6]: https://flex.symfony.com\n[7]: https://symfony.com/doc/current/messenger.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboshurik%2Ftelegrambotbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboshurik%2Ftelegrambotbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboshurik%2Ftelegrambotbundle/lists"}