diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index a3739f3..cbedcd8 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -14,6 +14,7 @@ use TgBotLib\Methods\Logout; use TgBotLib\Methods\SendAnimation; use TgBotLib\Methods\SendAudio; + use TgBotLib\Methods\SendChatAction; use TgBotLib\Methods\SendContact; use TgBotLib\Methods\SendDice; use TgBotLib\Methods\SendDocument; @@ -52,6 +53,7 @@ case SEND_CONTACT = 'sendContact'; case SEND_POLL = 'sendPoll'; case SEND_DICE = 'sendDice'; + case SEND_CHAT_ACTION = 'sendChatAction'; /** * Executes a command on the provided bot with the given parameters. @@ -87,6 +89,7 @@ self::SEND_CONTACT => SendContact::execute($bot, $parameters), self::SEND_POLL => SendPoll::execute($bot, $parameters), self::SEND_DICE => SendDice::execute($bot, $parameters), + self::SEND_CHAT_ACTION => SendChatAction::execute($bot, $parameters) }; } } diff --git a/src/TgBotLib/Enums/Types/ChatActionType.php b/src/TgBotLib/Enums/Types/ChatActionType.php index 378430e..f5feb1f 100644 --- a/src/TgBotLib/Enums/Types/ChatActionType.php +++ b/src/TgBotLib/Enums/Types/ChatActionType.php @@ -8,9 +8,8 @@ case UPLOAD_PHOTO = 'upload_photo'; case RECORD_VIDEO = 'record_video'; case UPLOAD_VIDEO = 'upload_video'; - case RECORD_AUDIO = 'record_audio'; - case UPLOAD_AUDIO = 'upload_audio'; - case UPLOAD_DOCUMENT = 'upload_document'; + case RECORD_VOICE = 'record_voice'; + case CHOOSE_STICKER = 'choose_sticker'; case FIND_LOCATION = 'find_location'; case RECORD_VIDEO_NOTE = 'record_video_note'; case UPLOAD_VIDEO_NOTE = 'upload_video_note'; diff --git a/src/TgBotLib/Methods/SendChatAction.php b/src/TgBotLib/Methods/SendChatAction.php new file mode 100644 index 0000000..525a972 --- /dev/null +++ b/src/TgBotLib/Methods/SendChatAction.php @@ -0,0 +1,47 @@ +value; + } + + return (bool)self::executeCurl(self::buildPost($bot, Methods::SEND_CHAT_ACTION->value, $parameters)); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'action' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id' + ]; + } + } \ No newline at end of file diff --git a/tests/TgBotLib/Methods/SendChatActionTest.php b/tests/TgBotLib/Methods/SendChatActionTest.php new file mode 100644 index 0000000..ba8385c --- /dev/null +++ b/tests/TgBotLib/Methods/SendChatActionTest.php @@ -0,0 +1,127 @@ +setAutoRetry(true); + } + + /** + * Tests the basic `sendVenue` functionality + * + * @return void + */ + public function testTypingAction(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::TYPING + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testUploadPhoto(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::UPLOAD_PHOTO + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testRecordVideo(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::RECORD_VIDEO + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testUploadVideo(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::UPLOAD_VIDEO + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testRecordVoice(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::RECORD_VOICE + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testChooseSticker(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::CHOOSE_STICKER + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testFindLocation(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::FIND_LOCATION + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testRecordVideoNote(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::RECORD_VIDEO_NOTE + ); + + $this->assertIsBool($result); + sleep(5); + } + + public function testUploadVideoNote(): void + { + $result = self::$bot->sendChatAction( + chat_id: TEST_CHAT_ID, + action: ChatActionType::UPLOAD_VIDEO_NOTE + ); + + $this->assertIsBool($result); + sleep(5); + } +} \ No newline at end of file