forked from piterskiy/etuts-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.php
62 lines (55 loc) · 1.76 KB
/
webhook.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// requirements
require 'vendor/autoload.php';
require_once 'config.php';
// file_get_contents('https://api.telegram.org/bot'.$token.'/sendMessage?chat_id=92454&text=debug');
require 'main-controller.php';
use Telegram\Bot\Api;
// connecting
$telegram = new Api($token);
// get user message
$updates = $telegram->getWebhookUpdates();
$message = $updates->getMessage();
$callback_query = $updates->getCallbackQuery();
// log_debug("ok");
if ($message != null) {
$chat_id = (int) $message->getChat()->getId();
$text = $message->getText();
$message_id = $message->getMessageId();
$username = $message->getFrom()->getUsername();
$user = $message->getFrom();
$username = $user->getUsername();
$fullname = $user->getFirstName() . ' ' . $user->getLastName();
try {
$db = new Database($db_name, $db_user, $db_pass, $chat_id, $message_id);
// vahid tests
/*if ($chat_id == 92454) {
}*/
// mamad tests
/*if ($chat_id == 117990761) {
}*/
// shahryar tests
/*if ($chat_id == 97778738) {
}*/
$state = get_chat_state($text, $username, $fullname);
if (!is_cancel_command($text, $chat_id, $message_id, $message))
if (!handle_state($state, $chat_id, $text, $message_id, $message))
if (!run_keyboard_button($text, $chat_id, $message_id, $message))
run_commands($text, $chat_id, $message_id, $message);
} catch (Exception $e) {
log_debug($e->getPrevious());
}
}
elseif ($callback_query != null) {
$id = $callback_query->getId();
$from = $callback_query->getFrom();
$chat_id = $from->getId();
$message = $callback_query->getMessage();
$data = $callback_query->getData();
try {
$db = new Database($db_name, $db_user, $db_pass, $chat_id);
run_callback_queries($id, $from, $message, $data);
} catch (Exception $e) {
log_debug($e->getPrevious());
}
}