How to send Emoji with Telegram Bot API?
To send an emoji using the Telegram Bot API in PHP, you can use the sendMessage method and include the emoji in the text of the message.
To send an emoji using the Telegram Bot API in PHP, you can use the sendMessage method and include the emoji directly in the text of the message. For example, to send the "thumbs up" emoji, you would use the following code:
Example of sending an emoji using the Telegram Bot API in PHP
<?php
$bot_token = 'YOUR_BOT_TOKEN';
$chat_id = 12345678;
$emoji = "\u{1F44D}"; // Thumbs up emoji using Unicode escape
$text = "This is a message with a thumbs up emoji: " . $emoji;
$url = "https://api.telegram.org/bot{$bot_token}/sendMessage";
$data = ["chat_id" => $chat_id, "text" => $text];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
$result = json_decode($response, true);
if ($result['ok']) {
echo "Message sent successfully.";
} else {
echo "API Error: " . $result['description'];
}
} else {
echo "Failed to connect to Telegram API.";
}
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Learn object oriented PHP</div>
You can find the Unicode code point for any emoji you want to use, and then apply the \u{...} syntax in PHP to include it in your message.