1. Go to this page and download the library: Download php-brasil/telegram library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-brasil / telegram example snippets
use PhpBrasil\Telegram\Bot;
$telegram = new Bot(env('BOT_TOKEN'));
$input = File::read('php://input');
$body = JSON::decode($input, true);
$telegram = new Bot(environment('APP_TOKEN'));
if (environment('APP_DEBUG')) {
$telegram->info(
get($body, 'message.message_id'),
$body
);
}
use App\Actions\OtherWise;
use App\Telegram\Bot;
return function (Bot $bot) {
$bot->text('.*', OtherWise::class);
};
$bot->text('^Hello|^Hi', function($bot) {
return $bot->reply('Nice to meet you');
});
$bot->text('How much is (?<n1>.*) \+ (?<n2>.*)\?', function (Bot $bot, Match $match) {
$parameters = $match->get('$parameters');
if (count($parameters) !== 2) {
return $bot->reply('Can`t resolve this math');
}
$sum = get($parameters, 'n1') + get($parameters, 'n2');
return $bot->reply("That is easy, the answer is `{$sum}`");
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.