Naser.Sadeghi Naser.Sadeghi - 1 year ago 106
C# Question

My Telegram bot does not get the updates and cannot respond

This is the piece of code that I'm using but after a while it stopped working:

namespace My_bot
{
class Program
{
private static ReplyKeyboardMarkup mainMenu;

private static string botToken = "xxxx";
static void Main(string[] args)
{
mainMenu = new ReplyKeyboardMarkup
{
Keyboard =
new KeyboardButton[][]
{
new KeyboardButton[] {new KeyboardButton("Main Menu") } ,
new KeyboardButton[] {new KeyboardButton("About Us") }
}

};
Task.Run(() => RunBot());
Console.ReadKey();
}

public static async Task RunBot()
{
var bot = new TelegramBot(botToken);
var me = await bot.MakeRequestAsync(new GetMe());
Console.WriteLine("My username is: {0}", me.Username);
long offset = 0;

while (true)
{
var updates = await bot.MakeRequestAsync(new GetUpdates() { Offset = offset });
foreach (var update in updates)
{
offset = update.UpdateId + 1;
var text = update.Message.Text;
Console.WriteLine("User with ID {0} send the this request: {1}", update.Message.Chat.Id, text);

if (text == "/start" && text != null)
{
var req = new SendMessage(update.Message.Chat.Id, "Hi, please choose one of the following items:") { ReplyMarkup = mainMenu };
await bot.MakeRequestAsync(req);
continue;
}
else
{
var req = new SendMessage(update.Message.Chat.Id, "Sorry, I cannot understand what you say. Please try again") { ReplyMarkup = mainMenu };
await bot.MakeRequestAsync(req);
continue;
}

}
}
}
}
}


For more information, I have to say that it returns bot's username correctly, but it does not receive the updates therefore it cannot answer to the updates too. For those who want to know, I'm using NetTelegramBotApi to implement this bot in C#.
Please help me, thanks.

Answer Source

This issue is fixed automatically. I think there was a problem with Telegram server at the moment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download