Reputation: 145
I have a generic function to send menus via telegram bots (like below) , but I don't know how to add icons on these menus ( the way mypokerbot do, check image) . Any hint?
function SendGenericMenu ($chatid) {
$lista=array("A", "B", "C");
$text="Choose:";
global $bottoken;
$replyMarkup = array(
'keyboard' => $lista,
);
$encodedMarkup = json_encode($replyMarkup);
$content = array(
'chat_id' => $chatid,
'reply_markup' => $encodedMarkup,
'text' => "$text"
);
$ch = curl_init();
$url="https://api.telegram.org/bot$bottoken/SendMessage";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
}
Upvotes: 3
Views: 19878
Reputation: 1980
A very simpler way is to write a scrap message( do not send) in telegram with emoji's you like. then copy/paste that text (include emoji) to your code. They will copy flawlessly. The whole proccess shown in this picture: Emoji Icons copy/paste
Upvotes: 1
Reputation: 11
You can store all your emojis in Emoji class as constants as ihoru proposed and append them as pengrad suggests. Yet you don't necessarily have to store unicode values of emojis in constants. You can copy paste emojis as strings from, say, http://emojipedia.org/ and that should work fine as well + in some IDE's on some operating systems e.g. Macs emojis will be actually represented in human-understandable form.
Upvotes: 1
Reputation: 1990
In MyPokerBot we use associative list of emojis and commands for them. In main loop of checking "what method of code should we call" it checks if text starts with that emoji and call it's command.
Example:
protected $shortCmds = [
Emoji::CMD_MAIN_MENU => '/start',
Emoji::CMD_STOP => '/stop',
];
Upvotes: 2
Reputation: 8283
You should use emoji, taking from here:
http://apps.timwhitlock.info/emoji/tables/unicode
Clicking on Unicode
column you can get values in different encodings.
Concatenate emoji string with your message to build your keyboard text.
For Java it will be:
String s = new String(new byte[]{(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0x81}, "UTF-8");
or
String s = "\uD83D\uDE4C" + "myKeyboardTest";
For PHP I think something like this:
"\xF0\x9F\x98\x81" . "your super keyboard"
Upvotes: 8