PHP code example of m1lkin / looksmaxxer

1. Go to this page and download the library: Download m1lkin/looksmaxxer 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/ */

    

m1lkin / looksmaxxer example snippets


use Looksmaxxer\Bot;
use Looksmaxxer\Models\Update;
use Looksmaxxer\Client;
use Looksmaxxer\Models\Keyboard\InlineKeyboard;
use Looksmaxxer\Models\Keyboard\Button;
use Looksmaxxer\Builders\MessageBuilder;

$bot = new Bot('TOKEN');

// 1. Отправляем кнопку запроса
$bot->onCommand('start', function(Update $update, Client $client) {
    $kb = InlineKeyboard::create()
        ->addRow(Button::requestGeoLocation('Где я?', quick: true));
        
    $client->sendMessage(
        MessageBuilder::create(chatId: $update->chatId)
            ->text('Нажми на кнопку ниже:')
            ->inlineKeyboard($kb)
    );
});

// 2. Обрабатываем ответ
$bot->onLocation(function(Update $update, Client $client) {
    $location = $update->message->getLocation();
    echo "Широта: {$location->latitude}, Долгота: {$location->longitude}";
});

// Запуск (Long Polling для тестов)
$bot->start();

// webhook.php
er\Bot;

$bot = new Bot('TOKEN');

$bot->onMessage(function($update, $client) {
    // Ваша логика
    $client->sendMessage(
        \Looksmaxxer\Builders\MessageBuilder::create(chatId: $update->chatId)->text('Привет из Webhook!')
    );
});

// Обработка входящего запроса
$bot->handleWebhook();

$bot->onCallbackQuery('confirm_order', function(Update $update, Client $client) {
    // Пользователь нажал кнопку с payload "confirm_order"
    $client->sendMessage(
        MessageBuilder::create(chatId: $update->chatId)->text('Заказ подтвержден!')
    );
});

$bot->onCommand('help', function($u, $c) { /* ... */ });

$bot->onText('/купи|продай/i', function($u, $c) {
    // Сработает на сообщения "купи", "Продай" и т.д.
});