Add SendContact method with corresponding test.

This commit is contained in:
netkas 2024-10-10 12:47:37 -04:00
parent 012fc4fe0f
commit 561542bc62
3 changed files with 115 additions and 0 deletions

View file

@ -0,0 +1,72 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Objects\Message;
use TgBotLib\Objects\ReplyParameters;
class SendContact extends Method
{
/**
* Use this method to send phone contacts. On success, the sent Message is returned.
*
* @param Bot $bot
* @param array $parameters
* @return Message
* @throws TelegramException
*/
public static function execute(Bot $bot, array $parameters = []): Message
{
// Handle reply parameters
if (isset($parameters['reply_parameters']) && $parameters['reply_parameters'] instanceof ReplyParameters)
{
$parameters['reply_parameters'] = $parameters['reply_parameters']->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',
];
}
}