-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtelebot.php
More file actions
103 lines (103 loc) · 3.54 KB
/
Copy pathtelebot.php
File metadata and controls
103 lines (103 loc) · 3.54 KB
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
<?php
class TeleBotLib {
const API_URL = 'https://api.telegram.org/bot';
public $token;
public function __construct($token = null) {
$this->setToken($token);
}
public function setToken($token = null) {
$this->token = ($token !== null) ? $token : 'setDefaultKey';
}
public function sendMessage($chatId, $text, $parseMode = "html") {
$url = self::API_URL . $this->token . '/sendmessage';
$postData = array(
'chat_id' => $chatId,
'text' => $text,
'parse_mode' => $parseMode
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
public function sendDocument($chatId, $text, $documentURL) {
$url = self::API_URL . $this->token . '/senddocument';
$postData = array(
'chat_id' => $chatId,
'document' => $documentURL,
'caption' => $text,
'parse_mode' => 'html'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
public function editMessage($chatId, $messageId, $text) {
$url = self::API_URL . $this->token . '/editmessagetext';
$postData = array(
'chat_id' => $chatId,
'message_id' => $messageId,
'text' => $text,
'parse_mode' => "html"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
public function editMessageCaption($chatId, $messageId, $caption) {
$url = self::API_URL . $this->token . '/editmessagecaption';
$postData = array(
'chat_id' => $chatId,
'message_id' => $messageId,
'caption' => $caption,
'parse_mode' => "html"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
public function pinChatMessage($chatId, $messageId) {
$url = self::API_URL . $this->token . '/pinchatmessage';
$postData = array(
'chat_id' => $chatId,
'message_id' => $messageId,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
}