1. Go to this page and download the library: Download mammothcoding/maxoxide 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/ */
mammothcoding / maxoxide example snippets
Maxoxide\Bot;
use Maxoxide\Context;
use Maxoxide\Dispatcher;
$bot = Bot::fromEnv(); // reads MAX_BOT_TOKEN from the environment
$dp = new Dispatcher($bot);
$dp->onCommand('/start', function (Context $ctx) {
if ($ctx->update->message !== null) {
$ctx->bot->sendMarkdownToChat(
$ctx->update->message->chatId(),
'Hello!'
);
}
});
$dp->onMessage(function (Context $ctx) {
if ($ctx->update->message !== null) {
$text = $ctx->update->message->text() ?? '(no text)';
$ctx->bot->sendTextToChat($ctx->update->message->chatId(), $text);
}
});
$dp->startPolling();
use Maxoxide\AttachmentKind;
use Maxoxide\Filter;
$dp->onCommand('/start', $handler); // specific command
$dp->onMessage($handler); // any new message
$dp->onEditedMessage($handler); // message edit
$dp->onCallback($handler); // any callback
$dp->onCallbackPayload('btn:ok', $handler); // exact payload
$dp->onBotStarted($handler); // first bot start
$dp->onBotAdded($handler); // bot added to a chat
$dp->onBotStopped($handler); // user stopped the bot
$dp->onDialogMuted($handler); // private dialog muted
$dp->onMessageChatCreated($handler); // chat button created a chat
$dp->onFilter(fn($u) => ..., $handler); // custom predicate
$dp->on($handler); // every update
$dp->onUpdate(
Filter::message()
->andFilter(Filter::chat($chatId))
->andFilter(Filter::textContains('ping')),
$handler
);
$dp->onUpdate(Filter::hasAttachmentType(AttachmentKind::FILE), $handler);
$dp->onUpdate(Filter::hasMedia(), $handler);
$dp->onUpdate(Filter::unknownUpdate(), $handler);
$dp->onRawUpdate($handler); // raw JSON for every update
$dp->onStart($handler); // once before polling starts
$dp->task(300, $handler); // periodic task while polling
use Maxoxide\Button;
use Maxoxide\KeyboardPayload;
use Maxoxide\NewMessageBody;
$keyboard = new KeyboardPayload([
[
Button::callback('Yes', 'answer:yes'),
Button::callback('No', 'answer:no'),
],
[
Button::link('Website', 'https://max.ru'),
Button::clipboard('Copy code', 'promo-123'),
],
[
Button::requestContact('Share contact'),
Button::requestGeoLocation('Share location'),
],
]);
$body = NewMessageBody::text('Are you sure?')->withKeyboard($keyboard);
$bot->sendMessageToChat($chatId, $body);
use Maxoxide\NewAttachment;
use Maxoxide\NewMessageBody;
use Maxoxide\UploadType;
$token = $bot->uploadFile(UploadType::IMAGE, './photo.jpg', 'photo.jpg', 'image/jpeg');
$body = NewMessageBody::text('Here is a photo!')
->withAttachment(NewAttachment::image($token));
$bot->sendMessageToChat($chatId, $body);
$bot->sendImageToChat($chatId, './photo.jpg', 'photo.jpg', 'image/jpeg', 'Here is a photo!');
$bot->sendVideoToUser($userId, './clip.mp4', 'clip.mp4', 'video/mp4');
$bot->sendFileBytesToChat($chatId, $bytes, 'report.pdf', 'application/pdf', 'Report');
// webhook.php -- this file is exposed via your HTTPS URL
use Maxoxide\Bot;
use Maxoxide\Dispatcher;
use Maxoxide\WebhookReceiver;
$bot = Bot::fromEnv();
$dp = new Dispatcher($bot);
$dp->onCommand('/start', function ($ctx) {
$ctx->bot->sendTextToChat($ctx->update->message->chatId(), 'Hello!');
});
// Pass the same secret that you used in SubscribeBody
WebhookReceiver::handle($dp, getenv('WEBHOOK_SECRET') ?: null);
use Maxoxide\SubscribeBody;
$body = new SubscribeBody('https://your-domain.com/webhook.php');
$body->secret = 'my_secret_123';
$bot->subscribe($body);