kaveh
kaveh

Reputation: 11

call back query data from inline keyboard

I'm trying to get the data from an inline keyboard, I've searched a lot but unfortunately didn't get my answer and non of codes worked for me. Here's my code please help me

    static void Main(string[] args){
       InlineKeyboardButton[][] buttons =
       new InlineKeyboardButton[][]{
       new InlineKeyboardButton[]{newInlineKeyboardButton() { Text = "show Channel", CallbackData = "Data1" }},
       new InlineKeyboardButton[]{new InlineKeyboardButton() { Text = "show Website", CallbackData = "Data2" }}};

       inlineKeyboardMarkup = new InlineKeyboardMarkup() { InlineKeyboard = buttons };

            Task.Run(() => RunBot());
            Console.ReadLine();
        } // End of main method

       public static async Task RunBot(){
           while (true){
                var u = await bot.MakeRequestAsync(new GetUpdates() { Offset 
                = offset });
                foreach (var update in u)
                {
                    offset = update.UpdateId + 1;
                    var text = update.Message.Text;

                    // here I want to get the data like this, but it doesn't work
                    if (update.ChosenInlineResult != null){
                        Console.WriteLine("Chosen Inline Result: " + 
                        update.ChosenInlineResult.ToString());
                    }

            switch(text){
                case "Something":{
                            var req = new SendMessage(update.Message.Chat.Id, "راهنما") { ReplyMarkup = inlineKeyboardMarkup };
                            await bot.MakeRequestAsync(req);
                            break;
                    }
                }
            }
        }
    }

Upvotes: 1

Views: 2229

Answers (1)

AvangSoft
AvangSoft

Reputation: 66

you must replace this

  if (update.ChosenInlineResult != null){
                    Console.WriteLine("Chosen Inline Result: " + 
                    update.ChosenInlineResult.ToString());
 }

with something like This :

if (update.CallbackQuery != null)
 {
    Console.WriteLine(val.CallbackQuery.Message+"-"+val.CallbackQuery.Data);
 }

Upvotes: 1

Related Questions