Answer the question
In order to leave comments, you need to log in
Telegram. How to handle user responses to a bot message?
Good day!
How to handle user responses to a bot message? That is, for example:
Bot:
Enter the name of the stock/s in the following format: "MOEX, AFLT"
SBER, CHMF
public class PredictCommand : Command
{
public override string Name => "predict";
public override async Task Execute(Message message, ITelegramBotClient client)
{
var chatId = message.Chat.Id;
string ms = null;
var users = BufferUsers.GetInstance().Users;
foreach (var i in users)
{
if (chatId == i.ChatId)
{
ms = "Введите название акции/й в следующем формате: MOEX, AFLT";
break;
}
else
{
ms = "Вы незарегестрированы! Воспользуйтесь командой /reg. ";
return;
}
}
await client.SendTextMessageAsync(chatId, ms, parseMode: ParseMode.Markdown, replyMarkup: null);
GettingResponse(chatId).Wait();
}
public async Task GettingResponse(long chatId)
{
var client = Bot.GetInstance().Get();
var bf = BufferUsers.GetInstance(); // Класс с листом где хранятся пользователи
int offset = 0;
int timeout = 0;
while (true)
{
var updates = await client.GetUpdatesAsync(offset, timeout);
foreach (var update in updates)
{
var message = update.Message;
foreach (var i in bf.Users)
{
if (chatId == i.ChatId)
{
foreach (var j in message.Text.Split(','))
{
i.Securities.Add(new Security(j));
}
break;
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
1. You seem to have a bug in the Execute method - the loop looks very strange. I would simplify it to
const string ms = "Введите название акции/й в следующем формате: MOEX, AFLT";
if(users.Any(user => user.ChatId != chatId)) return;
while (true)
{
var updates = await client.GetUpdatesAsync(offset, timeout);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question