-
Notifications
You must be signed in to change notification settings - Fork 3
/
robot.php
117 lines (84 loc) · 2.08 KB
/
robot.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
** @httd1 - t.me/httd1 (Telegram)
** https://github.com/httd1
*
** Bot Markdown simples. (https://github.com/httd1/simplebotmarkdown)
*
*/
include 'func.class.php';
define ('TOKEN','<TOKEN_BOT>');
define ('USER_BOT','@robot');
$tlg=new Tlg (TOKEN);
if (empty ($tlg->data ())){
// Somente urls em https
$url='https://'.$_SERVER ['HTTP_HOST'].$_SERVER ['REQUEST_URI'];
$ret=$tlg->APITelegram ('setWebhook', [
'url' => $url
]);
if ($ret->ok){
echo 'Ok,url de Webhook definida para '.$url;
}else {
echo 'Ops! Houve um erro ao definir url de Webhook.
ERRO: '.$ret->error_code.' DESCRIPTION: '.$ret->description;
}
exit ();
}
$texto = $tlg->text ();
$username = $tlg->username ();
$nome = $tlg->name ();
$chatID = $tlg->chat_id ();
$pref = ($tlg->lang () != 'en' && $tlg->lang () != 'es' && $tlg->lang () != 'pt') ? 'en' : $tlg->lang ();
// Textos em várias línguas
include 'idiomas.php';
// Resposta Inline
if (isset ($tlg->data ()->inline_query)){
$build = [[
'type' => 'article',
'id' => '0',
'title' => USER_BOT,
'description' => $tlg->data ()->inline_query->query,
'input_message_content' => [
'message_text' => $tlg->data ()->inline_query->query,
'parse_mode' => 'markdown'
]
]];
$query = [
'inline_query_id' => $tlg->data ()->inline_query->id,
'results' => json_encode($build)
];
$tlg->APITelegram ('answerInlineQuery', $query);
exit;
}
switch ($texto):
case '/start':
$tlg->APITelegram ('sendMessage', [
'chat_id' => $chatID,
'text' => $lang [$pref]['start'],
'parse_mode' => 'html',
'disable_web_page_preview' => 'true'
]);
break;
case '/ajuda':
case '/help':
$tlg->APITelegram ('sendMessage',[
'chat_id' => $chatID,
'text' => $lang [$pref]['help']
]);
break;
default:
// Envia texto estilizado com markdown.
$send=$tlg->APITelegram ('sendMessage', [
'chat_id' => $chatID,
'text' => $texto,
'parse_mode' => 'markdown',
'disable_web_page_preview' => 'true'
]);
if (!$send->ok){
$tlg->APITelegram ('sendMessage', [
'chat_id' => $chatID,
'text' => $lang [$pref]['erro']
]);
}
endswitch;
?>