1. Go to this page and download the library: Download mk4u/larabot 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/ */
mk4u / larabot example snippets
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::post('/bot', function (Request $request) {
app('tgram')->run();
});
namespace App\Http\Controllers;
use Mk4U\TGram\Bot;
class TelegramController extends Controller
{
public function sendMessage(Bot $bot)
{
$bot->sendMessage(
chat_id: '123456789',
text: 'Hello from Laravel!'
);
return response()->json(['status' => 'sent']);
}
}
use Mk4U\TGram\Bot;
// Method 1: via type-hinting (recommended)
public function myMethod(Bot $bot) { ... }
// Method 2: via alias 'tgram' (recommended)
$bot = app('tgram');
// Method 3: via app() helper
$bot = app(Bot::class);
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Bot extends Facade
{
protected static function getFacadeAccessor()
{
return \Mk4U\TGram\Bot::class;
}
}
public function example(Bot $bot)
{
$bot->sendMessage(
chat_id:'123456789',
text:'Hello World!'
);
}
public function withKeyboard(Bot $bot)
{
use Mk4U\TGram\Core\Factories\InlineButton;
$keyboard = Mk4U\TGram\Core\Factories\Keyboard::inline()
->row([
Mk4U\TGram\Core\Factories\InlineButton::make('👥 Community')
->url('https://t.me/myGroup')
])->build();
$bot->sendMessage(
chat_id:'123456789',
text:'Join my group!',
reply_markup:$keyboard
);
}
public function handleCallback(Bot $bot)
{
$bot->answerCallbackQuery(
callback_query_id:$callback_query_id,
text:'Action completed!'
);
}