dev-master
9999999-devSilex Service Provider for the Telegram SDK
The Requires
The Development Requires
by Agustin Houlgrave
Wallogit.com
2017 © Pedro Peláez
Silex Service Provider for the Telegram SDK
A Silex service provider to integrate the Telegram PHP SDK, (*2)
composer require ahoulgrave/silex-tg-service-provider dev-master
<?php
use Telegram\Bot\Silex\Provider\TelegramServiceProvider;
$app = new Silex\Application();
$app->register(new TelegramServiceProvider(), [
'telegram.bot_api' => '<Your bot api token>',
'telegram.commands' => [
\My\Telegram\Command\AwesomeCommand::class,
]
]);
If your are using a webhook to fetch the updates, you can register the Controller Provider to handle the request for you., (*3)
$app->mount('/telegram-web-hook', new TelegramControllerProvider());
Your webhook should be https://youdomain.com/telegram-web-hook/ (Note the trailing slash), (*4)
Now, when telegram sends you the updates, the controller will look for the right command and handle it., (*5)
You can extend the Telegram\Bot\Silex\ApplicationAwareCommand class, so your command can access the container., (*6)
For example:, (*7)
<?php
namespace My\Telegram\Command;
use Telegram\Bot\Silex\ApplicationAwareCommand;
class AwesomeCommand extends ApplicationAwareCommand
{
/**
* @inheritdoc
*/
protected $name = 'hello';
/**
* @inheritdoc
*/
public function handle($arguments)
{
$update = $this->getUpdate();
$app = $this->getApplication();
$app['monolog']->info($update->getMessage()->getText());
$this->replyWithMessage(['text' => 'Hi there!']);
}
}
Remember to register all of your commands (see Usage), (*8)
Read this for more details on the commands system, (*9)
(The MIT License), (*10)
Copyright (C) 2016 by Agustin Houlgrave, (*11)
Silex Service Provider for the Telegram SDK