Longman\TelegramBot\Entities\Entity::tryMention PHP 메소드

tryMention() 공개 메소드

Mention the user with the username otherwise print first and last name if the $escape_markdown argument is true special characters are escaped from the output
public tryMention ( boolean $escape_markdown = false ) : string | null
$escape_markdown boolean
리턴 string | null
    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;
    }