tgbotlib/src/TgBotLib/Objects/ForceReply.php

75 lines
2.1 KiB
PHP
Raw Normal View History

2023-02-13 14:30:39 -05:00
<?php
2024-10-02 00:18:12 -04:00
namespace TgBotLib\Objects;
2023-02-13 14:30:39 -05:00
use TgBotLib\Interfaces\ObjectTypeInterface;
class ForceReply implements ObjectTypeInterface
{
2024-10-04 21:11:26 -04:00
private bool $force_reply;
private ?string $inline_field_placeholder;
private bool $selective;
2023-02-13 14:30:39 -05:00
/**
* Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply'
*
* @return bool
*/
public function isForceReply(): bool
{
return $this->force_reply;
}
/**
* Optional. The placeholder to be shown in the input field when the reply is active; 1-64 characters
*
* @return string|null
*/
public function getInlineFieldPlaceholder(): ?string
{
return $this->inline_field_placeholder;
}
/**
* Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are
* @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id),
* sender of the original message.
*
* @return bool
*/
public function isSelective(): bool
{
return $this->selective;
}
/**
2024-10-04 21:11:26 -04:00
* @inheritDoc
2023-02-13 14:30:39 -05:00
*/
public function toArray(): array
{
return [
'force_reply' => $this->force_reply,
'inline_field_placeholder' => $this->inline_field_placeholder,
'selective' => $this->selective,
];
}
/**
2024-10-04 21:11:26 -04:00
* @inheritDoc
2023-02-13 14:30:39 -05:00
*/
2024-10-04 21:11:26 -04:00
public static function fromArray(?array $data): ?ForceReply
2023-02-13 14:30:39 -05:00
{
2024-10-04 21:12:24 -04:00
if($data === null)
{
return null;
}
2023-02-13 14:30:39 -05:00
2024-10-04 21:12:24 -04:00
$object = new self();
2023-02-14 17:35:16 -05:00
$object->force_reply = $data['force_reply'] ?? false;
2023-02-13 14:30:39 -05:00
$object->inline_field_placeholder = $data['inline_field_placeholder'] ?? null;
2023-02-14 17:35:16 -05:00
$object->selective = $data['selective'] ?? false;
2023-02-13 14:30:39 -05:00
return $object;
}
}