【问题标题】:How Miniaturize telegram bot button如何使电报机器人按钮小型化
【发布时间】:2018-03-28 02:26:40
【问题描述】:

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

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

它太大了,我不喜欢这个。

如何将电报按钮小型化?

我想我需要这个:resize_keyboard

但我不知道如何将其用于小型化按钮。

这是我的功能要求:

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

我怎样才能缩小这个按钮?

【问题讨论】:

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


    【解决方案1】:
    var_dump(
        makeHTTPRequest('sendMessage',[
            'chat_id'=>userid,
            'text'=>"Text",
            'reply_markup'=>json_encode(array('keyboard'=> [['⬅️','Button','?']],'resize_keyboard' => true))
        ])
    );
    

    【讨论】:

      【解决方案2】:

      你是什么意思?你想改变按钮的大小还是说表情符号?

      如果要调整大小,您的函数应如下所示:

      $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 );
      }
      
      ?>
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 我的朋友它的内联按钮。这不是我的答案。我想要Miniaturize 按钮。不是内联键盘按钮,我想要小型化键盘按钮,您可以在我的代码中看到!
        猜你喜欢
        • 1970-01-01
        • 2017-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-27
        • 2019-05-13
        • 1970-01-01
        • 2022-10-19
        相关资源
        最近更新 更多