-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebhook_bot.php
More file actions
36 lines (29 loc) · 906 Bytes
/
webhook_bot.php
File metadata and controls
36 lines (29 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Webhook Example
* This example shows how to use RubikaPhp with a webhook
*/
require_once(__DIR__ . '/../lib/autoload.php');
use RubikaPhp\Core\Bot;
use RubikaPhp\Filters\Filters;
// Initialize the bot
$bot = new Bot('YOUR_BOT_TOKEN_HERE');
// Setup webhook (run this once to configure)
// $bot->setEndpoint('https://yourdomain.com/webhook.php');
// Define handlers
$bot->onUpdate(Filters::text(), function($bot, $update) {
$bot->chatId($update->new_message->chat_id)
->text('Echo: ' . $update->new_message->text)
->sendMessage();
});
$bot->onUpdate(Filters::command('start'), function($bot, $update) {
$bot->chatId($update->new_message->chat_id)
->text('Bot is running via webhook!')
->sendMessage();
});
// Process webhook request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$bot->run();
} else {
echo "Webhook endpoint is ready.";
}