03
AugTelegraph is a Laravel package for fluently interacting with Telegram Bots made by def:studio
Telegraph::message('hello world')
->keyboard(Keyboard::make()->buttons([
Button::make('Delete')->action('delete')->param('id', '42'),
Button::make('open')->url('https://test.it'),
]))->send();
You can install the package via composer:
composer require defstudio/telegraph
Publish and launch required migrations:
php artisan vendor:publish --tag="telegraph-migrations"
php artisan migrate
Optionally, you can publish the config file with:
php artisan vendor:publish --tag="telegraph-config"
/newbot
, to start creating a new Bot and setting its name and username.token
./setjoingroups
command to @BotFather, and select your bot privacy:Any number of bots can be created, both programmatically and through an artisan command
You can add a new bot issuing the dedicated artisan command:
php artisan telegraph:new-bot
If you are implementing a custom bot creation logic, you can create a new bot using the TelegraphBot model:
$bot = TelegraphBot::create([
'token' => $token,
'name' => $name,
]);
A webhook lets your bot answer commands issued from telegram chats and buttons inside messages
php artisan telegraph:set-webhook {bot_id}
the bot_id
argument is mandatory if you have created more than one bot
A webhook can be created programmatically for a bot by calling its registerWebhook()
method
/** @var TelegraphBot $bot */
$bot->registerWebhook()->send();
Associating one or more chats to a bot, it is enabled to send messages to that chat and interact with commands
php artisan telegraph:new-chat {bot_id}
the bot_id
argument is mandatory if you have created more than one bot
After a bot and at least one chat have been set up, this package can be used to post new messages:
use DefStudio\Telegraph\Models\TelegraphChat;
/** @var TelegraphChat $chat */
$chat->html("<strong>Hello!</strong>\n\nI'm here!")->send();
Here’s the basic introduction of this package but this package has a lot more features and options. If you want to dig more, you can visit its complete documentation here.
Published at : 03-08-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project