2
votes

I have created the test Telegram bot console app using sample from this link https://github.com/TelegramBots/Telegram.Bot.Examples

There is my main

public static async Task Main()
{
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    Bot = new TelegramBotClient(Configuration.BotToken);
    var me = await Bot.GetMeAsync();
    Console.Title = me.Username;

    var cts = new CancellationTokenSource();

    // StartReceiving does not block the caller thread. Receiving is done on the ThreadPool.
    Console.WriteLine($"Bot.Timeout= {Bot.Timeout}");

    //Bot.Timeout = TimeSpan.FromMilliseconds(30000);
    Bot.StartReceiving(
        new DefaultUpdateHandler(HandleUpdateAsync, HandleErrorAsync),
        cts.Token
    );

    Console.WriteLine($"Start listening for @{me.Username}");

    Console.ReadLine();

    // Send cancellation request to stop bot
    cts.Cancel();
}

I run it on Windows 10 - it works fine. But when I run it on the Windows 7 machine I receive the exception:

Bot.Timeout= 00:01:40 Start listening for @my123_bot HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.d__541.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.<ReceiveAsync>d__3.MoveNex t() HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__541.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.d__3.MoveNex t()

What is the reason and how to fix it?

2
": terminat ed by other getUpdates request; make sure that only one bot instance is running" There are multiple request to the same getUpdates(). Are you sure the bot is not running on the W10 machine, or maybe hidden in the background? - 0stone0
It may be the reason: if I run 2 bots on 2 machines? @ years ago I run my old bot on 3 machines and they worked - ZedZip
Yea, you can't / shouldn't run a manual bot that calls getUpdates() on multiple instances. Or, you should create a real solid solution with web-hooks - 0stone0
Maybe those old bots were perfectly timed so they never did the same request? If you can ensure that there will always be x seconds between the calls, and you'll never tell telegram you've saw a message that another bot did not yet saw, it should work. But that's just not the way to go ;) - 0stone0
Ok, it seems the web-hooks may be the solution. Create answer and I will mark it. - ZedZip

2 Answers

3
votes

As described in the comments;

: terminat ed by other getUpdates request; make sure that only one bot instance is running

Indicates that getUpdates() is being called at the same time.

To prevent this, either stop the other bots, or create a bot that will receive a web-hook HTTP POST request on update.

You should ensure that each message is handled by the bot(s) before you tell Telegram the message has been seen by the getUpdate() offset param.

0
votes

make sure that only one bot instance is running

I was able to solve this problem by revoking and updating bot token. This worked because I think it stopped all the bot instances that were using the old token.