public function tryMention($escape_markdown = false)
{
//TryMention only makes sense for the User and Chat entity.
if (!($this instanceof User || $this instanceof Chat)) {
return null;
}
//Try with the username first...
$name = $this->getProperty('username');
$is_username = $name !== null;
if ($name === null) {
//...otherwise try with the names.
$name = $this->getProperty('first_name');
$last_name = $this->getProperty('last_name');
if ($last_name !== null) {
$name .= ' ' . $last_name;
}
}
if ($escape_markdown) {
$name = $this->escapeMarkdown($name);
}
return ($is_username ? '@' : '') . $name;
}