-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.php
More file actions
43 lines (36 loc) · 1.09 KB
/
Copy pathindex.php
File metadata and controls
43 lines (36 loc) · 1.09 KB
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
37
38
39
40
41
42
43
<?php
require_once('botpesa.php');
$botpesa = new BotPesa;
// Replace with your bot API key
$apiKey = 'YOUR BOT API KEY'; // Talk to BotFather
$apiURL = 'https://api.telegram.org/bot' . $apiKey . '/';
$rawData = file_get_contents('php://input');
if (!$rawData) {
// Direct browser access, just show a message and exit
echo "This endpoint is for Telegram webhook only.";
http_response_code(200);
exit;
}
$update = json_decode($rawData);
// Ensure $update->message exists
if (!isset($update->message->text)) {
// Invalid webhook payload
http_response_code(200);
exit;
}
// Get the incoming update from Telegram
// $update = json_decode(file_get_contents('php://input'));
$text = $update->message->text;
// Handle different commands
if (preg_match('#^pay#i', $text) === 1) {
$botpesa->handle($update, $apiURL, $text);
} elseif ($text == '/start') {
$botpesa->about($update, $apiURL);
} elseif ($text == 'Help') {
$botpesa->help($update, $apiURL);
} elseif ($text == 'About') {
$botpesa->about($update, $apiURL);
} else {
$botpesa->unknown($update, $apiURL);
}
?>