Longman\TelegramBot\Entities\Message::getText PHP Method

getText() public method

For text messages, the actual UTF-8 text of the message, 0-4096 characters.
public getText ( boolean $without_cmd = false ) : string
$without_cmd boolean
return string
    public function getText($without_cmd = false)
    {
        $text = $this->getProperty('text');
        if ($without_cmd && ($command = $this->getFullCommand())) {
            if (strlen($command) + 1 < strlen($text)) {
                $text = substr($text, strlen($command) + 1);
            } else {
                $text = '';
            }
        }
        return $text;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Insert Edited Message request in db
  *
  * @param Entities\Message &$edited_message
  *
  * @return bool If the insert was successful
  * @throws TelegramException
  */
 public static function insertEditedMessageRequest(Message &$edited_message)
 {
     if (!self::isDbConnected()) {
         return false;
     }
     $from = $edited_message->getFrom();
     $chat = $edited_message->getChat();
     $chat_id = $chat->getId();
     $edit_date = self::getTimestamp($edited_message->getEditDate());
     $entities = $edited_message->getEntities();
     //Insert chat
     self::insertChat($chat, $edit_date);
     //Insert user and the relation with the chat
     self::insertUser($from, $edit_date, $chat);
     try {
         $sth = self::$pdo->prepare('INSERT INTO `' . TB_EDITED_MESSAGE . '`
             (
             `chat_id`, `message_id`, `user_id`, `edit_date`, `text`, `entities`, `caption`
             )
             VALUES (
             :chat_id, :message_id, :user_id, :date, :text, :entities, :caption
             )');
         $message_id = $edited_message->getMessageId();
         $from_id = $from->getId();
         $text = $edited_message->getText();
         $caption = $edited_message->getCaption();
         $sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
         $sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
         $sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT);
         $sth->bindParam(':date', $edit_date, \PDO::PARAM_STR);
         $var = [];
         if (is_array($entities)) {
             foreach ($entities as $elm) {
                 $var[] = json_decode($elm, true);
             }
             $entities = json_encode($var);
         } else {
             $entities = null;
         }
         $sth->bindParam(':text', $text, \PDO::PARAM_STR);
         $sth->bindParam(':entities', $entities, \PDO::PARAM_STR);
         $sth->bindParam(':caption', $caption, \PDO::PARAM_STR);
         return $sth->execute();
     } catch (\PDOException $e) {
         throw new TelegramException($e->getMessage());
     }
 }
All Usage Examples Of Longman\TelegramBot\Entities\Message::getText