Telegram bot keybord send via JSON

后端 未结 1 622
醉酒成梦
醉酒成梦 2021-01-22 09:10

I\'m using MS Bot Framework. I want to sen custom keyboard to user, so i try to reply message with this JSON:

        public async Task Post([From         


        
相关标签:
1条回答
  • 2021-01-22 10:01

    Add another bracket to your keyboard.( one more array) like this:

    ""keyboard"":[[[""1""],[""2""]],[[""3""]],[[""4""],[""5""],[""6""]]]
    

    know there is triple array inside each other instead of two of your code.

    Documentation

    a part of working code:

        $keyboard = [
        'keyboard' =>
            [[['text' => '1'], ['text' => '2']], [['text' => '3']], [['text' => '4'], ['text' => '5'], ['text' => '6']]],
        'one_time_keyboard' => true,
    ];
    $markup = json_encode($keyboard, true);
    $data = [
        'chat_id' => sender_user_id($update),
        'text' => 'JUST A TEXT',
        'reply_markup' => $markup];
    
    
    $ch = curl_init();
    $url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/SendMessage';
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    curl_close($ch);
    
    0 讨论(0)
提交回复
热议问题