1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BPT\telegram; |
4
|
|
|
use BPT\constants\fileTypes; |
5
|
|
|
use BPT\tools; |
6
|
|
|
use BPT\types\forceReply; |
7
|
|
|
use BPT\types\inlineKeyboardMarkup; |
8
|
|
|
use BPT\types\message; |
9
|
|
|
use BPT\types\replyKeyboardMarkup; |
10
|
|
|
use BPT\types\replyKeyboardRemove; |
11
|
|
|
use BPT\types\responseError; |
12
|
|
|
use stdClass; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* telegram class , Adding normal method call to request class and a simple name for being easy to call |
16
|
|
|
*/ |
17
|
|
|
class telegram extends request { |
18
|
|
|
public function __call (string $name, array $arguments) { |
19
|
|
|
return request::$name(...$arguments); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* download telegram file with file_id to destination location |
24
|
|
|
* |
25
|
|
|
* It has 20MB download limit(same as telegram) |
26
|
|
|
* |
27
|
|
|
* e.g. => tools::downloadFile('test.mp4'); |
28
|
|
|
* |
29
|
|
|
* e.g. => tools::downloadFile('test.mp4','file_id_asdadadadadadad); |
30
|
|
|
* |
31
|
|
|
* @param string|null $destination destination for save the file |
32
|
|
|
* @param string|null $file_id file_id for download, if not set, will generate by request::catchFields method |
33
|
|
|
* |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
|
|
public static function downloadFile (string|null $destination = null, string|null $file_id = null): bool { |
37
|
|
|
return tools::downloadFile(self::fileLink($file_id), $destination); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function fileLink(string|null $file_id = null): bool|string { |
41
|
|
|
$file = self::getFile($file_id); |
42
|
|
|
if (!isset($file->file_path)) { |
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
return $file->link(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* send file with only file_id |
50
|
|
|
* |
51
|
|
|
* e.g. => tools::sendFile('file_id_asdadsadadadadadada'); |
52
|
|
|
* |
53
|
|
|
* e.g. => tools::sendFile('file_id_asdadsadadadadadada','hello'); |
54
|
|
|
* |
55
|
|
|
* @param string $file_id |
56
|
|
|
* @param int|string|null $chat_id |
57
|
|
|
* @param int|null $message_thread_id default : null |
58
|
|
|
* @param string|null $caption |
59
|
|
|
* |
60
|
|
|
* @return message|bool|responseError |
61
|
|
|
*/ |
62
|
|
|
public static function sendFile (string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message|bool|responseError { |
63
|
|
|
$type = tools::fileType($file_id); |
64
|
|
|
return match ($type) { |
65
|
|
|
fileTypes::VIDEO => self::sendVideo($file_id, $chat_id, null, null, null, null, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
66
|
|
|
fileTypes::VIDEO_NOTE => self::sendVideoNote($file_id, $chat_id, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
67
|
|
|
fileTypes::ANIMATION => self::sendAnimation($file_id, $chat_id, null, null, null, null, $caption, $parse_mode, $caption_entities, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
68
|
|
|
fileTypes::AUDIO => self::sendAudio($file_id, $chat_id, $caption, $parse_mode, $caption_entities, null, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
69
|
|
|
fileTypes::PHOTO, |
70
|
|
|
fileTypes::PROFILE_PHOTO => self::sendPhoto($file_id, $chat_id, $caption, $parse_mode, $caption_entities, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
71
|
|
|
fileTypes::VOICE => self::sendVoice($file_id, $chat_id, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
72
|
|
|
fileTypes::STICKER => self::sendSticker($file_id, $chat_id, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
73
|
|
|
fileTypes::DOCUMENT => self::sendDocument($file_id, $chat_id, null, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer, $message_thread_id), |
74
|
|
|
default => false, |
75
|
|
|
}; |
76
|
|
|
} |
77
|
|
|
} |