-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bot.php
67 lines (51 loc) · 1.45 KB
/
test_bot.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
62
63
64
65
66
67
<?php
//TODO: save user request in db
header('Content-Type: application/json');
/*
Input format:
{
"update_id": 440148654,
"inline_query": {
"id": "817150061370106850",
"from": {
"id": 190257574,
"is_bot": false,
"first_name": "Kolodi",
"username": "kolodim",
"language_code": "en-US"
},
"query": "ally",
"offset": ""
}
}
*/
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update)
{
exit("no input");
}
include "lib.php";
include "db.php";
include "process_query.php";
$db = new DB();
// put user in db
$user = $update['inline_query']['from'];
$user["is_bot"] = intval(boolval($user["is_bot"]));
$sql = "INSERT INTO tg_user (id, is_bot, first_name, username, language_code) VALUES (?,?,?,?,?)";
$stmt = $db->pdo->prepare($sql);
$stmt->execute(array_values($user));
// put query in db
$inline_query = $update["inline_query"];
$inline_query["from"] = $user["id"];
$sql = "INSERT INTO inline_query (id, user, query, offset) VALUES (?,?,?,?)";
$stmt = $db->pdo->prepare($sql);
$stmt->execute(array_values($inline_query));
$q = $update['inline_query']['query'];
$inlineQueryId = $update['inline_query']['id'];
$tg = new TG('bot_token');
$responce = GetInlineAnswer($q, $db);
$responce->inline_query_id = $inlineQueryId;
//echo $responce->inline_query_id;
$data_string = json_encode($responce);
//$result = $tg->SendInlineAnswerToTG($data_string);