justdmitry / NetTelegramBotApi

C# client library for building Telegram bot
MIT License
74 stars 28 forks source link

Timeout property in the MakeRequest don't work? #48

Closed rogercorrea closed 7 years ago

rogercorrea commented 7 years ago

Please,

I am trying use the Timeout property in the MakeRequestAsync to call GetUpdates but don't work. And I went to see the source code and not finded the property in the function.

She is used? My internet is unstable and I receive errors in all the time. Thanks!

justdmitry commented 7 years ago

MakeRequestAsync expect only request object in parameters. What Timeout you are speaking about?

rogercorrea commented 7 years ago

My code to GetUpdates: updates = bot.MakeRequestAsync(new GetUpdates() { Offset = offset, Timeout = 120 }).Result;

rogercorrea commented 7 years ago

Sorry! It correct is timeout in the GetUpdates, sure? But I set 120 seconds and don't work for me.

justdmitry commented 7 years ago

This timeout is not about your internet connection. It's for Telegram server - interval for long-polling where there is no messages available, see docs

rogercorrea commented 7 years ago

Ok. My code generates one exception for the long pool. Haven't relation with the timeout in the GetUpdates?

Request failed (status code 409): Conflict: terminated by other long poll or webhook

rogercorrea commented 7 years ago

I'm using a web proxy. It is very important.

My code example:

            var me = bot.MakeRequestAsync(new GetMe()).Result;

            string msg = string.Empty;  //Resposta do robô para o usuário
            long chatId = 0;            //Id do usuário que receberá a mensagem

            long offset = 0;
            Update[] updates = null;
            while (true)
            {
                try
                {
                    updates = bot.MakeRequestAsync(new GetUpdates() { Offset = offset, Timeout = 120 }).Result;

                    if (updates != null)
                    {
                        //Laço que trata cada nova requisição recebida
                        foreach (var update in updates)
                        {
                            offset = update.UpdateId + 1;`
justdmitry commented 7 years ago

This code is returned by Telegram server, I'm not from Telegram team and can only guess...

Do you have webhook installed/registered?

Or may be you call GetUpdates periodically with interval less than 120 seconds - may be connection failed, but proxy still waits for response from Telegram server...

rogercorrea commented 7 years ago

But he work in the first time and not more. And for more that 120 seconds. I can trying for the long time and only work if I restart the Windows service. I don't understand because it occur.

My first line included GetMe: var me = bot.MakeRequestAsync(new GetMe()).Result;

justdmitry commented 7 years ago

It's too many "extra" factors - service, proxy, etc.

Try on sample project (add Timeout to GetUpdates) and try with good internet and without proxies. Then add "bad factors" back one by one to find where is the problem.

justdmitry commented 7 years ago

Closing as no answer. Please reopen if you are experiencing same problems with test project.