diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 079a7bf..0294ac4 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -30,6 +30,7 @@ case SEND_PHOTO = 'sendPhoto'; case SEND_AUDIO = 'sendAudio'; case SEND_DOCUMENT = 'sendDocument'; + case SEND_VIDEO = 'sendVideo'; /** * Executes a command on the provided bot with the given parameters. @@ -54,6 +55,7 @@ self::SEND_PHOTO => SendPhoto::execute($bot, $parameters), self::SEND_AUDIO => SendAudio::execute($bot, $parameters), self::SEND_DOCUMENT => SendDocument::execute($bot, $parameters), + self::SEND_VIDEO => SendVideo::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendVideo.php b/src/TgBotLib/Methods/SendVideo.php new file mode 100644 index 0000000..12749c5 --- /dev/null +++ b/src/TgBotLib/Methods/SendVideo.php @@ -0,0 +1,137 @@ +value; + } + + if(isset($parameters['caption_entities']) && is_array($parameters['caption_entities'])) + { + $entities = []; + foreach($parameters['caption_entities'] as $entity) + { + if($entity instanceof MessageEntity) + { + $entities[] = $entity->toArray(); + } + else + { + $entities[] = $entity; + } + } + $parameters['caption_entities'] = $entities; + } + + if(isset($parameters['reply_parameters']) && $parameters['reply_parameters'] instanceof ReplyParameters) + { + $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); + } + + if(isset($parameters['reply_markup']) && $parameters['reply_markup'] instanceof ObjectTypeInterface) + { + $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + } + + // Handle file uploads + $hasLocalVideo = isset($parameters['video']) && is_string($parameters['video']) && file_exists($parameters['video']) && is_file($parameters['video']); + $hasLocalThumb = isset($parameters['thumbnail']) && is_string($parameters['thumbnail']) && file_exists($parameters['thumbnail']) && is_file($parameters['thumbnail']); + + if ($hasLocalVideo || $hasLocalThumb) + { + $files = []; + + if ($hasLocalVideo) + { + $files['video'] = $parameters['video']; + unset($parameters['video']); + } + + if ($hasLocalThumb) + { + $files['thumbnail'] = $parameters['thumbnail']; + unset($parameters['thumbnail']); + } + + if (count($files) > 1) + { + // Multiple files to upload + $curl = self::buildMultiUpload($bot, Methods::SEND_VIDEO->value, $files, $parameters); + } + else + { + // Single file to upload + $fileParam = array_key_first($files); + $curl = self::buildUpload($bot, Methods::SEND_VIDEO->value, $fileParam, $files[$fileParam], $parameters); + } + + return Message::fromArray(self::executeCurl($curl)); + } + + // If no local files to upload, use regular POST method + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::SEND_VIDEO->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'video' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id', + 'duration', + 'width', + 'height', + 'thumbnail', + 'caption', + 'parse_mode', + 'caption_entities', + 'show_caption_above_media', + 'has_spoiler', + 'supports_streaming', + 'disable_notification', + 'protect_content', + 'message_effect_id', + 'reply_parameters', + 'reply_markup' + ]; + } +} \ No newline at end of file