Telegram bot bundle on top of telegram-bot/api library
$ composer require boshurik/telegram-bot-bundle<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new BoShurik\TelegramBotBundle\BoShurikTelegramBotBundle,
);
// ...
}BoShurikTelegramBotBundle:
resource: "@BoShurikTelegramBotBundle/Resources/config/routing.yml"
prefix: /_telegram/<some-secret>bo_shurik_telegram_bot:
api:
token: "%telegram_bot_api_token%"
name: "%telegram_bot_name%" /** @var TelegramBot\Api\BotApi $api */
$api = $this->container->get('bo_shurik_telegram_bot.api');For more info see Usage section in telegram-bot/api library
bin/console telegram:updatesFor more information see official documentation
bin/console telegram:webhook [<url>] [<path-to-certificate>]bin/console telegram:webhookFor more information see official documentation
Commands must implement \BoShurik\TelegramBotBundle\Telegram\Command\CommandInterface
There is \BoShurik\TelegramBotBundle\Telegram\Command\AbstractCommand you can start with
To register command: add tag bo_shurik_telegram_bot.command to service definition
app.telegram.command:
class: AppBundle/Telegram/Command/SomeCommand
tags:
- { name: bo_shurik_telegram_bot.command }There is predefined \BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand. You need to register it:
app.telegram.command.help:
class: BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand
arguments:
- "@bo_shurik_telegram_bot.command_pool"
tags:
- { name: bo_shurik_telegram_bot.command }For more complex application (e.g. conversations) you can listen for TelegramEvents::UPDATE event
/**
* @param UpdateEvent $event
*/
public function onUpdate(UpdateEvent $event)
{
$update = $event->getUpdate();
$message = $update->getMessage();
}