request(new Request("https://api.telegram.org/bot$token/sendMessage?".http_build_query([ 'text' => $message, 'parse_mode' => $parse_mode, 'entities' => json_encode($entities), 'chat_id' => $dest ]))); return json_decode($res->getBody()->buffer(), true)['result']; }; $result = $sm("*This is a ❤️ test*", parse_mode: "MarkdownV2"); // Convert a message+entities back to HTML $entities = new Entities($result['text'], $result['entities']); var_dump($entities->toHTML()); // This is a ❤️ test // Modify $entities as needed $entities->message = "A message with ❤️ emojis"; // EntityTools::mb* methods compute the length in UTF-16 code units, as required by the bot API. $entities->entities[0]['length'] = EntityTools::mbStrlen($entities->message); // then resend: $sm($entities->message, entities: $entities->entities); // Convert HTML to an array of entities locally $entities = Entities::fromHtml("This is a ❤️ nested test"); $sm($entities->message, entities: $entities->entities); // Convert markdown to an array of entities locally $entities = Entities::fromHtml("This is a ❤️ nested test"); $sm($entities->message, entities: $entities->entities); // See https://github.com/danog/telegram-entities for the full list of available methods!