-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot-tel-fungsi.php
52 lines (46 loc) · 1.16 KB
/
bot-tel-fungsi.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
<?php
if (!defined('RA')) {
die('Tidak dapat diakses langsung.');
}
function apiRequest($method, $data)
{
if (!is_string($method)) {
error_log("Nama method harus bertipe string!\n");
return false;
}
if (!$data) {
$data = [];
} elseif (!is_array($data)) {
error_log("Data harus bertipe array\n");
return false;
}
$url = 'https://api.telegram.org/bot'.$GLOBALS['token'].'/'.$method;
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
function sendApiMsg($chatid, $text, $parse_mode = false, $msg_reply_id = false, $disablepreview = true)
{
$method = 'sendMessage';
$data = [
'chat_id' => $chatid,
'text' => $text
];
if ($parse_mode) {
$data['parse_mode'] = $parse_mode;
}
if ($disablepreview) {
$data['disable_web_page_preview'] = $disablepreview;
}
if ($msg_reply_id) {
$data['reply_to_message_id'] = $msg_reply_id;
}
$result = apiRequest($method, $data);
}