Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call back query #60

Open
SecretV opened this issue Sep 4, 2017 · 3 comments
Open

Call back query #60

SecretV opened this issue Sep 4, 2017 · 3 comments
Labels

Comments

@SecretV
Copy link

SecretV commented Sep 4, 2017

hi can you please write an example of creating an in line keyboard with a call back data and how to receive the call back data?

please answer soon!

@XcJoo
Copy link

XcJoo commented Sep 5, 2017

Hi, here is a very short example in Vb.Net. hopefully it helps:

' Create message and send
Dim sMessage = New SendMessage(ChatID, MessageText) With {.ReplyMarkup = New InlineKeyboardMarkup With {
  .InlineKeyboard = {
    {New InlineKeyboardButton With {.Text = "Button Text", .CallbackData = "Callback Value"}}.ToArray
  }.ToArray
}}
Dim sReturn = teleBot.MakeRequestAsync(sMessage).Result

' ----------------------------------------------
' Callback in a e.g. aspx-file
Dim tBot As New TelegramBot(ACCESS_TOKEN)

Dim strPostRequest As String = ""
Try
  Request.InputStream.Position = 0
  Dim inputStream As New IO.StreamReader(Request.InputStream)
  strPostRequest = inputStream.ReadToEnd()
Catch ex As Exception
End Try

Dim update As Update = tBot.DeserializeUpdate(strPostRequest)

If update IsNot Nothing Then 
  ' The Callback Value is in update.CallbackQuery.Data
End If

@justdmitry
Copy link
Owner

@XcJoo is right - just put InlineKeyboard with some InlineKeyboardButton into your message.

When button is pressed - you will receive Update with CallbackQuery populated.

@rasools13
Copy link

hi @SecretV , here is a example
` ///
while (stopme == true)
{
try
{
var Updates = await bot.MakeRequestAsync(new GetUpdates() { Offset = offset });

                    if (Updates != null)
                    {
                        foreach (var UpD in Updates)
                        {
                            if (UpD.Message != null)
                            {
                                offset = UpD.UpdateId + 1;
                                string chatTxt = UpD.Message.Text;
                                if (chatTxt == "/start")
                                {
                                   InlineKeyboardMarkup btnInline = new InlineKeyboardMarkup();
                                    InlineKeyboardButton btn1 = new InlineKeyboardButton { Text = "btn Inline Txt", CallbackData = "callback value" };
                                    btnInline.InlineKeyboard = new[] { new[] { btn1 } };
                                    await bot.MakeRequestAsync(new SendMessage(UpD.Message.Chat.Id, "This is a test message") { ReplyMarkup = btnInline });
                                }
                            }
                            else if (UpD.CallbackQuery != null)
                            {
                                offset = UpD.UpdateId + 1;
                                string t1 = UpD.CallbackQuery.Data.ToString();
                                long chID = UpD.CallbackQuery.Message.Chat.Id;
                                long MId = UpD.CallbackQuery.Message.MessageId;

                                if (t1 == "callback value")
                                {
                                    await bot.MakeRequestAsync(new EditMessageText(chID, MId, "This is callback answer") { ReplyMarkup = btnInline });
                                }
                                AnswerCallbackQuery an = new AnswerCallbackQuery(UpD.CallbackQuery.Id);
                                await bot.MakeRequestAsync(an);
                            }

                        }
                    }
                }
                catch (BotRequestException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants