sergio-item/telegram is a Laravel package for telegram bot utilities.
It currently has 0 GitHub stars and 7 downloads on Packagist (latest version 1.0.2).
Install it with composer require sergio-item/telegram.
Discover more Laravel packages by sergio-item
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Package
You can install the package via composer:
composer require sergio-item/telegram
Add Telegram variables to your .env file
TELEGRAM_BOT=""
TELEGRAM_CHAT_IDS="" # Can be multiple values separated by commas or semicolons
TELEGRAM_MANAGE_WEBHOOK_URL="" # Default is telegram-manage-webhook
Use the Telegram Facade to send a notification
use SergioItem\Telegram\Facades\Telegram;
Telegram::sendNotification($message);
Webhook related commands
php artisan telegram:set-webhook {url?}
php artisan telegram:remove-webhook
php artisan telegram:get-webhook-info
Get updates command (offset option available)
php artisan telegram:get-updates
php artisan telegram:get-updates --offset {updateId}
php artisan telegram:get-updates -O {updateId}
Send Notification command
php artisan telegram:send-notification {message}
# View all the commands available in the telegram namespace
php artisan list telegram
# Display help for a command
php artisan help telegram:<command>
To automatically reply to user messages, you can use the webhook to receive user messages on your server.
First use the command to set the webhook url
php artisan telegram:set-webhook {url?}
Create App\Services\TelegramBotWebhookManagerService in your project with the required method manageResponseMessage
e.g
<?php
namespace App\Services;
use SergioItem\Telegram\Interfaces\TelegramBotWebhookManagerInterface;
class TelegramBotWebhookManagerService implements TelegramBotWebhookManagerInterface
{
/**
* @param string $text
* @param null $data
* @return string
*/
public function manageResponseMessage(string $text, $data = null)
{
switch (strtolower($text)) {
case 'hi':
case 'hello':
return 'Hi ' . $data->firstName . '! welcome to this bot';
break;
case 'chat':
case 'id':
return 'Your chat id is: ' . $data->chatId;
break;
default:
// return null; // No message will be sent
return 'Sorry, I couldn\'t understand your message.';
break;
}
}
}
The data object should have the following attributes
$data->chatId
$data->isBot
$data->firstName
$data->lastName
$data->username
$data->languageCode
$data->date
$data->messageId
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.