PHP wrapper for Telegram bots
This project uses Composer. To use the project, just add it to your dependencies.
$ composer require hetisniels/telegram-wrapper
Without Composer
It is possible you dont like Composer or you just want to get the source and use it. In this case download the latest release in releases page. Note: You need to make your own autoloader for this to work!
<?php
class HelloWorldCommand implements \Telegram\Commands\ICommand
{
public function call($name, $arguments, $caller)
{
$keyboard = $caller->getBot()->createKeyboard(); // Alternative: $keyboard = new KeyboardBuilder();
$keyboard = $keyboard->button('A')->button('B')->row()->button('C')->button('D')->row()->setResizable(true)->setOneTime(true)->keyboard();
$caller->reply('Hello World!', false, $keyboard);
}
public function getDescription()
{
return 'Sends the popular "Hello World" text.';
}
public function getUsage()
{
return '<command>';
}
}
$bot = new Telegram\Bot('API_TOKEN');
$bot->addCommand('helloworld', new HelloWorldCommand());
$bot->work();
And now, just send the message "/helloworld" to the bot!
<?php
$bot = new Telegram\Api('API_TOKEN');
$bot->getUpdates(); // Returns array of Update
An custom command handler is needed when using the API. The API provides only the methods & types from Telegram.