Add methods to retrieve text and commands from messages

This commit is contained in:
netkas 2024-11-04 01:16:55 -05:00
parent 6b9ecaa153
commit 7cfd6c0c5f

View file

@ -991,6 +991,39 @@
return $this->reply_markup;
}
/**
* Retrieves any available text, prioritizing 'text' over 'caption'.
*
* @return string|null
*/
public function getAnyText(): ?string
{
return $this->text ?? $this->caption;
}
/**
* Retrieves the command from the text if it exists.
*
* @return string|null
*/
public function getCommand(): ?string
{
if ($this->text === null)
{
return null;
}
$text = trim($this->text);
if (!str_starts_with($text, '/'))
{
return null;
}
$parts = explode(' ', $text);
return ltrim($parts[0], '/');
}
/**
* @inheritDoc
*/