diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index a90e085..d15e582 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\SendContact; use TgBotLib\Methods\SendDocument; use TgBotLib\Methods\SendLocation; use TgBotLib\Methods\SendMediaGroup; @@ -46,6 +47,7 @@ case SEND_MEDIA_GROUP = 'sendMediaGroup'; case SEND_LOCATION = 'sendLocation'; case SEND_VENUE = 'sendVenue'; + case SEND_CONTACT = 'sendContact'; /** * Executes a command on the provided bot with the given parameters. @@ -78,6 +80,7 @@ self::SEND_MEDIA_GROUP => SendMediaGroup::execute($bot, $parameters), self::SEND_LOCATION => SendLocation::execute($bot, $parameters), self::SEND_VENUE => SendVenue::execute($bot, $parameters), + self::SEND_CONTACT => SendContact::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendContact.php b/src/TgBotLib/Methods/SendContact.php new file mode 100644 index 0000000..d2b0a99 --- /dev/null +++ b/src/TgBotLib/Methods/SendContact.php @@ -0,0 +1,72 @@ +toArray(); + } + + // Handle reply markup + if (isset($parameters['reply_markup']) && method_exists($parameters['reply_markup'], 'toArray')) + { + $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + } + + // Make request + $curl = self::buildPost($bot, Methods::SEND_CONTACT->value, $parameters); + $result = self::executeCurl($curl); + + return Message::fromArray($result); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'phone_number', + 'first_name', + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id', + 'last_name', + 'vcard', + 'disable_notification', + 'protect_content', + 'message_effect_id', + 'reply_parameters', + 'reply_markup', + ]; + } + } diff --git a/tests/TgBotLib/Methods/SendContactTest.php b/tests/TgBotLib/Methods/SendContactTest.php new file mode 100644 index 0000000..8a8ea1e --- /dev/null +++ b/tests/TgBotLib/Methods/SendContactTest.php @@ -0,0 +1,40 @@ +setAutoRetry(true); + } + + /** + * Tests the sendContact method. + * + * @return void + */ + public function testSendContact(): void + { + + // Execute the method and retrieve the result + $result = self::$bot->sendContact( + chat_id: TEST_CHAT_ID, + phone_number: '18884074747', + first_name: 'FBI', + ); + + // Assert that the result is an instance of Message + $this->assertInstanceOf(Message::class, $result); + } + } +