Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Custom Dynamic Keyboard

Open sorenaa opened this issue 10 years ago • 6 comments

Hi, I have some command in my BOT (look like bellow sample), how can define custom keyboard? (I need a keyboard with 4 row, each button in a row) please help me :)

Sample: /start /GetNext /Status /DayInfo /Help

sorenaa avatar Jun 10 '16 08:06 sorenaa

see this comment

MrRoundRobin avatar Jun 10 '16 08:06 MrRoundRobin

@MrRoundRobin thanxxxxx

sorenaa avatar Jun 10 '16 08:06 sorenaa

using Telegram.Bot.Types?

MrRoundRobin avatar Jun 10 '16 08:06 MrRoundRobin

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;

namespace TelegramBot
{
    public static class KeyBoardHelper
    {
        public static ReplyKeyboardMarkup CreateMainMenu()
        {
            return new ReplyKeyboardMarkup
            {
                Keyboard = new[]
                {
                    new KeyboardButton[] // First Row
                    {
                        "A",
                        "B",
                    },
                    new KeyboardButton[] // Second Row
                    {
                        "C",
                        "D",
                    },
                }
            };

        }
    }
}

sorenaa avatar Jun 10 '16 08:06 sorenaa

Solved. "KeyboardButton[]" changed to "string[]" and worked fine!

sorenaa avatar Jun 10 '16 08:06 sorenaa

var rkm = new ReplyKeyboardMarkup();
var rows = new List<KeyboardButton[]>();
var cols = new List<KeyboardButton>();
for (var Index = 1; Index < 17; Index++)
{
    cols.Add(new KeyboardButton("" + Index));
    if (Index%4 != 0) continue;
    rows.Add(cols.ToArray());
    cols = new List<KeyboardButton>();
}
rkm.Keyboard = rows.ToArray();


await botClient.SendTextMessageAsync(
    message.Chat.Id,
    "Choose",
    replyMarkup: rkm);

https://stackoverflow.com/a/49364380/1770868

ahmadaghazadeh avatar Mar 19 '18 13:03 ahmadaghazadeh