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