stajor / telegram-bot
Telegram Bot
Installs: 6 723
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^5.0
README
PHP wrapper for Telegram's Bot API.
Installation
Add this line to your application's composer.json:
{ "require": { "stajor/telegram-bot": "^3.0" } }
and run composer update
Or run this command in your command line:
$ composer require stajor/telegram-bot
Telegram API support
All types and methods of the Telegram Bot API 3.6 are supported.
Configuration
First of all you need create your own bot and obtain a token
Usage
You can use Telegram::Bot::Api standalone
<?php $api = new \Telegram\Bot\Api('BOT TOKEN'); $user = $api->getMe();
Or by using CommandsHandler to receive updates from Telegram
Create command class
<?php use Telegram\Bot\Command; class StartCommand extends Command { /** * @var string Command Name */ protected $name = "start"; /** * @var string Command Description */ protected $description = "Start Command to get you started"; /** * @inheritdoc */ public function handle() { // This will send a message using `sendMessage` $this->replyWithMessage(['text' => 'Welcome to my Bot']); // Trigger another command dynamically from within this command $this->triggerCommand('help'); } }
In your controller add
<?php $handler = new CommandsHandler('BOT TOKEN'); $handler->addCommand(StartCommand::class); $handler->handle();
Send Photo
$api = new \Telegram\Bot\Api('BOT TOKEN'); $api->sendPhoto(['chat_id' => 123,'photo' => fopen('path_to_photo', 'rb')]);
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Stajor/telegram-bot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.