forked from pokepark/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl_json_response.php
56 lines (52 loc) · 2.49 KB
/
curl_json_response.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
<?php
/**
* Process response from telegram api.
* @param string $json_response Json response from Telegram
* @param string $json Json sent to Telegram
* @param int|string $identifier
* @return mixed
*/
function curl_json_response($json_response, $json, $identifier = false)
{
global $config;
// Write to log.
debug_log_incoming($json_response, '<-');
// Decode json response.
$response = json_decode($json_response, true);
// Validate response.
if ((isset($response['ok']) && $response['ok'] != true) || isset($response['update_id'])) {
info_log("{$json} -> {$json_response}", 'ERROR:');
} else {
if($identifier != false) {
if (isset($response['result']['chat']['type']) && in_array($response['result']['chat']['type'], ['channel','group','supergroup'])) {
// Set chat and message_id
$chat_id = $response['result']['chat']['id'];
$message_id = $response['result']['message_id'];
debug_log('Return data: Chat id: '.$chat_id.', message_id: '.$message_id.', type: '.$identifier);
if($identifier == 'trainer') {
debug_log('Adding trainermessage info to database now!');
insert_trainerinfo($chat_id, $message_id);
}else if ($identifier == 'overview') {
debug_log('Adding overview info to database now!');
$chat_title = $response['result']['chat']['title'];
$chat_username = isset($response['result']['chat']['username']) ? $response['result']['chat']['username'] : '';
insert_overview($chat_id, $message_id, $chat_title, $chat_username);
}else {
if(isset($response['result']['text']) && !empty($response['result']['text'])) {
$type = 'poll_text';
} else if(isset($response['result']['caption']) && !empty($response['result']['caption'])) {
$type = 'poll_photo';
} else if(isset($response['result']['venue']) && !empty($response['result']['venue'])) {
$type = 'poll_venue';
}else if(isset($response['result']['photo']) && !isset($response['result']['caption'])) {
$type = 'photo';
}
insert_cleanup($chat_id, $message_id, $identifier, $type);
}
}
}
}
// Return response.
return $response;
}
?>