Add methods to retrieve text and commands from messages
This commit is contained in:
parent
6b9ecaa153
commit
7cfd6c0c5f
1 changed files with 33 additions and 0 deletions
|
@ -991,6 +991,39 @@
|
||||||
return $this->reply_markup;
|
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
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue