PHP code example of gusaln / simple-tg-bot-api

1. Go to this page and download the library: Download gusaln/simple-tg-bot-api 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/ */

    

gusaln / simple-tg-bot-api example snippets


$botToken = '<bot token>';

$api = new \GusALN\TelegramBotApi\BotApi(
    $botToken,
    new \GusALN\TelegramBotApi\Client\GuzzleClient()
);

// If no ClientInterface is provided as second argument, a GuzzleClient is created by default.
$api = new \GusALN\TelegramBotApi\BotApi($botToken);

$userId = '<user id>';

$message = $api->sendMessage(
    new \GusALN\TelegramBotApi\MethodRequests\SendMessageRequest($userId, "Hello")
);

$editedMessage = $api->editMessageText(
    new \GusALN\TelegramBotApi\MethodRequests\EditMessageTextRequest(
        $message->chat->id,
        $message->messageId,
        "Good bye!"
    )
);

// omitted code
abstract class MenuButton implements JsonSerializable
{
    public const MENU_BUTTON_COMMANDS_TYPE = 'commands';
    public const MENU_BUTTON_WEB_APP_TYPE = 'web_app';
    public const MENU_BUTTON_DEFAULT_TYPE = 'default';
    // omitted code
}

$message = $api->sendMessage(
    new \GusALN\TelegramBotApi\MethodRequests\SendMessageRequest(
        $userId,
        "<b>bold</b>, <strong>bold</strong>, <i>italic</i>, <em>italic</em>",
        parseMode: \GusALN\TelegramBotApi\Enums\ParseMode::HTML
    )
);

$fetcher = new \GusALN\TelegramBotApi\WebhookUpdateFetcher();
$update = $fetcher->fetch($request);