首页 > 解决方案 > 文本c#下方的电报按钮

问题描述

bot中的电报文本下方有按钮我该怎么做?这是我能提供的关于这个的最大信息,因为我不知道它叫什么或什么。 在此处输入图像描述

var new_keyboard = new InlineKeyboardMarkup(
            new[]
                 {
                  new[]
                     {
                      new InlineKeyboardButton("step_1","step1") ,
                      },
                  new[]
                      {
                      new InlineKeyboardButton("step_2","step2"),
                      new InlineKeyboardButton("step_3","step3"),
                       },
                  new[]
                       {
                      new InlineKeyboardButton("step_4","step4"),
                       }
              });
api.EditMessageReplyMarkupAsync(chatid, messageid, replyMarkup: new_keyboard);

标签: c#telegramtelegram-bot

解决方案


文本消息下方的按钮称为InlineKeyboardMarkup,您可以使用方法传递它SendTextMessageAsync,或者默认为空,如下所示:

private void bot_OnMessage(object sender, MessageEventArgs msg)
{
    // Defining InlineKeyboardButtons
    List<List<InlineKeybordButton>> buttons = new List<List<InlineKeybordButton>>(/*Two button lines!*/2);

    // Defining Rows (As List of buttons)
    List<InlineKeybordButton> row1 = new List<InlineKeybordButton>(/*One button in first row!*/1);
    List<InlineKeybordButton> row2 = new List<InlineKeybordButton>(/*One button in second row!*/1);
    
    // Adding buttons to the rows:
    row1.Add(InlineKeyboardButton.WithUrl("Google", "https://www.google.com/"));
    row2.Add(InlineKeyboardButton.WithUrl("Bing", "https://www.bing.com/"));


    // Adding rows to the list:
    buttons.Add(row1);        
    buttons.Add(row2);
    
    // HERE:
    // Inline Keyboard
    InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup(buttons);
    bot.SendTextMessageAsync(msg.Chat, "Some text...", replyMarkup: keyborad);
}

推荐阅读