From 8c664e8127c21418f22c7cdcdbd1dd7a5efe8539 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 13 Aug 2023 21:11:32 -0400 Subject: [PATCH] * Updated `\TgBotLib\Bot::sendPhoto()` to accept URLs as a parameter for the `photo` field. * Updated `\TgBotLib\Bot::sendAudio()` to accept URLs as a parameter for the `audio` field. * Updated `\TgBotLib\Bot::sendDocument()` to accept URLs as a parameter for the `document` field. * Updated `\TgBotLib\Bot::sendVideo()` to accept URLs as a parameter for the `video` field. * Updated `\TgBotLib\Bot::sendAnimation()` to accept URLs as a parameter for the `animation` field. * Updated `\TgBotLib\Bot::sendVoice()` to accept URLs as a parameter for the `voice` field. --- CHANGELOG.md | 14 ++++++++++++ src/TgBotLib/Bot.php | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da02309..86cf12a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [6.7.1] - 2023-08-13 + +This update introduces a bug fix in a few functions + +### Fixed + * Updated `\TgBotLib\Bot::sendPhoto()` to accept URLs as a parameter for the `photo` field. + * Updated `\TgBotLib\Bot::sendAudio()` to accept URLs as a parameter for the `audio` field. + * Updated `\TgBotLib\Bot::sendDocument()` to accept URLs as a parameter for the `document` field. + * Updated `\TgBotLib\Bot::sendVideo()` to accept URLs as a parameter for the `video` field. + * Updated `\TgBotLib\Bot::sendAnimation()` to accept URLs as a parameter for the `animation` field. + * Updated `\TgBotLib\Bot::sendVoice()` to accept URLs as a parameter for the `voice` field. + + + ## [6.7.0] - 2023-08-10 This update accompanies the release of the [Telegram Bot API 6.7](https://core.telegram.org/bots/api#april-21-2023). diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index f56f352..7262df3 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -744,6 +744,14 @@ */ public function sendPhoto(string|int $chat_id, string $photo, array $options=[]): Message { + if(filter_var($photo, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendPhoto', array_merge($options, [ + 'chat_id' => $chat_id, + 'photo' => $photo + ]))); + } + if(file_exists($photo)) { return Message::fromArray($this->sendFileUpload('sendPhoto', 'photo', $photo, array_merge($options, [ @@ -787,6 +795,14 @@ */ public function sendAudio(string|int $chat_id, string $audio, array $options=[]): Message { + if(filter_var($audio, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendAudio', array_merge($options, [ + 'chat_id' => $chat_id, + 'audio' => $audio + ]))); + } + if(file_exists($audio)) { return Message::fromArray($this->sendFileUpload('sendAudio', 'audio', $audio, array_merge($options, [ @@ -827,6 +843,14 @@ */ public function sendDocument(string|int $chat_id, string $document, array $options=[]): Message { + if(filter_var($document, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendDocument', array_merge($options, [ + 'chat_id' => $chat_id, + 'document' => $document + ]))); + } + if(file_exists($document)) { return Message::fromArray($this->sendFileUpload('sendDocument', 'document', $document, array_merge($options, [ @@ -868,6 +892,14 @@ */ public function sendVideo(string|int $chat_id, string $video, array $options=[]): Message { + if(filter_var($video, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendVideo', array_merge($options, [ + 'chat_id' => $chat_id, + 'video' => $video + ]))); + } + if(file_exists($video)) { return Message::fromArray($this->sendFileUpload('sendVideo', 'video', $video, array_merge($options, [ @@ -909,6 +941,14 @@ */ public function sendAnimation(string|int $chat_id, string $animation, array $options=[]): Message { + if(filter_var($animation, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendAnimation', array_merge($options, [ + 'chat_id' => $chat_id, + 'animation' => $animation + ]))); + } + if(file_exists($animation)) { return Message::fromArray($this->sendFileUpload('sendAnimation', 'animation', $animation, array_merge($options, [ @@ -951,6 +991,14 @@ */ public function sendVoice(string|int $chat_id, string $voice, array $options=[]): Message { + if(filter_var($voice, FILTER_VALIDATE_URL)) + { + return Message::fromArray($this->sendRequest('sendVoice', array_merge($options, [ + 'chat_id' => $chat_id, + 'voice' => $voice + ]))); + } + if(file_exists($voice)) { return Message::fromArray($this->sendFileUpload('sendVoice', 'voice', $voice, array_merge($options, [ @@ -990,6 +1038,11 @@ */ public function sendVideoNote(string|int $chat_id, string $video_note, array $options=[]): Message { + if(filter_var($video_note, FILTER_VALIDATE_URL)) + { + throw new TelegramException('Sending video notes by a URL is currently unsupported'); + } + if(file_exists($video_note)) { return Message::fromArray($this->sendFileUpload('sendVideoNote', 'video_note', $video_note, array_merge($options, [