Answer the question
In order to leave comments, you need to log in
Bot for Telegram does not send InlineKeyboardMarkup keyboard. The first few times he sent, then stopped. Why is that?
I am learning how to write a bot for Telegram. I ran into a problem: I created a method in order to find out exchange rates, the user must enter a date in the YYYY.MM.DD format, then an api request is sent, the JSON file is parsed into an array of entities, on the basis of which InlineButton.WithCallbackData buttons are then formed. Then I send all this to the user's chat:
bot.SendTextMessageAsync(e.Message.From.Id, "Select the currency you want to know the rate of.", replyMarkup: new InlineKeyboardMarkup(buttons));
buttons is a jagged array of InlineButton.WithCallbackData.
But these buttons are either sent (and everything works fine) several times in a row, or they are not sent even once, although I went through the debugger: everything works as it should and the program reaches bot.SendTextMessageAsync, but the buttons may be sent, they may not be sent.
Here is the code from the method.
var date = e.Message.Text;
string url = $"https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date={date}&json";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
string response;
using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
{
response = streamReader.ReadToEnd();
}
currencyResponse.Currencies = JsonConvert.DeserializeObject<Currency[]>(response);
Currency[] currencies = currencyResponse.Currencies;
InlineKeyboardButton[][] buttons = new InlineKeyboardButton[currencies.Length / 4][];
int count = 0;
for (int i = 0; i < currencies.Length / 4; i++)
{
buttons[i] = new InlineKeyboardButton[currencies.Length / (currencies.Length / 4)];
for (int j = 0; j < buttons[i].Length; j++)
{
buttons[i][j] = InlineKeyboardButton.WithCallbackData($"{currencies[count].txt} {currencies[count].cc}");
count++;
}
}
bot.SendTextMessageAsync(e.Message.From.Id, "Оберіть валюту, курс якої хочете дізнатись.", replyMarkup: new InlineKeyboardMarkup(buttons)); // Здесь пользователю должна отослаться клавиатура для выбора
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question