如何微型化电报机器人按钮

时间:2017-10-16 14:15:23

标签: telegram-bot php-telegram-bot telegram-webhook

$media[]=['⬅️',''];

这是我的电报机器人按钮。

它非常大我不喜欢这个。

如何将电报按钮小型化?

我想我需要这个:resize_keyboard

但我不知道如何将它用于Miniaturize按钮。

我的功能要求:

var_dump(
    makeHTTPRequest('sendMessage',[
        'chat_id'=>userid,
        'text'=>"Text",
        'reply_markup'=>json_encode(array('keyboard'=> [['⬅️','Button','']]))
    ])
);

我如何微缩这个按钮?

3 个答案:

答案 0 :(得分:1)

var_dump(
    makeHTTPRequest('sendMessage',[
        'chat_id'=>userid,
        'text'=>"Text",
        'reply_markup'=>json_encode(array('keyboard'=> [['⬅️','Button','']],'resize_keyboard' => true))
    ])
);

答案 1 :(得分:1)

你是什​​么意思?你想改变按钮大小还是谈论表情符号?

如果要调整大小,您的功能应如下所示:

$reply_markup = array(
    'keyboard' => array(['⬅️','Button','']),
    'resize_keyboard' => true,
    'selective' => true
);

var_dump(
    makeHTTPRequest('sendMessage',[
        'chat_id'=>userid,
        'text'=>"Text",
        'reply_markup'=>$reply_markup
    ])
);

你可以使用表情符号作为unicode,短代码或复制原始图像。

如果您使用的是PHP,那么简单的方法是在按钮文本中插入Unicode或UTF-8字符。 此链接对PHP Emoji Table

更有用

另外,您可以在githubothers

上找到许多不同的示例

例如,我的第一个比萨饼机器人之一:)

<?php

define('TOKEN', '<token>');
define('URL', 'https://api.telegram.org/bot'.TOKEN.'/');

$bot = json_decode(file_get_contents('php://input'), true);
$chat = $bot["message"]["chat"]["id"];
$user = $bot["message"]["chat"]["first_name"].' '.$bot["message"]["chat"]["last_name"];
$text = $bot["message"]["text"];

$menuMsg = "Hello, ${user}! Enjoy a new Banana Pie. \xF0\x9F\x8D\x8C \xF0\x9F\x98\x8A";

if ( $text == "/start" ){

  $Menu = array(
    array("\xF0\x9F\x8D\xB4 Menu", "\xF0\x9F\x92\xB0 Checkout"),
    array("\xE2\x86\xAA Last oreder", "\xE2\x9D\x8C Cancel")
  );

  send_keyb(
    $chat,
    $menuMsg,
    $Menu
  );
}

function send_keyb( $chat, $msg, $keyb ){

  $content = array(
    'parse_mode' => 'HTML',
    'chat_id' => $chat,
    'text' => $msg,
    'reply_markup' => keyboard($keyb)
  );

  curlGET(
    URL."sendMessage?".http_build_query( $content )
  );
}

function keyboard( $keyb ){

  $reply = array(
    'keyboard' => $keyb,
    'one_time_keyboard' => true,
    'resize_keyboard' => true,
    'selective' => true
  );

  return json_encode( $reply, true );
}

function curlGET( $url ) {

  $menuIthem = curl_init(
    trim( $url )
  );

  curl_setopt(
    $menuIthem,
    CURLOPT_RETURNTRANSFER,
    true
  );

  $res = explode(
    "\nDATA=",
    curl_exec(
      $menuIthem
    )
  );

  curl_close( $menuIthem );

  return json_decode( $res[1], true );
}

?>

答案 2 :(得分:0)

您使用了错误的内联键盘格式,请参阅以下实例:

Awesome Telegram Bot