L
L
Lev Fedorov2019-08-29 14:24:14
C++ / C#
Lev Fedorov, 2019-08-29 14:24:14

How to add Inline buttons to Telegram?

There is a database in which certain data is stored, which I pull out using Entity, and according to their list, you need to create Inline buttons in a chat with a bot.

var inlineSelect = new InlineKeyboardMarkup(new[]
                            {
                                new[] {InlineKeyboardButton.WithCallbackData("name1","cd1") },
                                new[] {InlineKeyboardButton.WithCallbackData("name2","cd2") },
                                new[] {InlineKeyboardButton.WithCallbackData("name3","cd3") }
                            });

This is an example of how buttons are created manually. The question is how to create them through a loop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Fedorov, 2019-08-29
@blvckheart0

I'll answer the question myself

List<InlineKeyboardButton> list = new List<InlineKeyboardButton>();                       
foreach (string s in SomeList)
{
     list.Add(InlineKeyboardButton.WithCallbackData(s));
}
var inline = new InlineKeyboardMarkup(list);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question