Hello. My name is Milly, and I've been writing Telegram bots for a few years now. I used to write Telegram bots in PHP without any libraries. When I had to make a website, I learned about laravel and realized that Laravel has everything. I just lacked a library to work with the Telegram API in Laravel and decided to develop it myself.
Laragram: a Laravel package to integrate the Telegram bot API
Features
- It has every method of Telegram bot API that is fully documented.
- Update-objects, which are easy to handle, are documented too.
- FSM Routing
Now let's try to install it and send hello world.
First, install the Laragram package, and make sure that the database connection settings are correct!
composer require milly/laragram
Then run these commands to publish assets and config
php artisan vendor:publish --provider="Milly\Laragram\LaragramServiceProvider"
Add your telegram bot token to .env
TELEGRAM_BOT_TOKEN=123456789:XXXXXXXXXXXXXXXXXXXXXXXXXXX
Run migration to be able to use FSM-Routing
php artisan migrate
And we are ready to use telegram methods. Let's test the basic sendMessage method:
use \Milly\Laragram\Laragram;
Laragram::sendMessage(
'your_telegram_id',
null,
'Hello world'
);
When you run this code, you should get the message 'Hello world' from your telegram bot (you should have started the bot before). And that's it. Isn't it easy?
You can check out the full documentation from on github: https://github.com/Mirmuxsin/laragram
Top comments (0)