Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systematically stopping the WebHook bot from receiving messages #490

Open
fox-15 opened this issue Sep 29, 2023 · 1 comment
Open

Systematically stopping the WebHook bot from receiving messages #490

fox-15 opened this issue Sep 29, 2023 · 1 comment

Comments

@fox-15
Copy link

fox-15 commented Sep 29, 2023

Good afternoon
For my project I am using the Telegram.Bot v.19.0.0 library, doing some research and testing.
I took the example Telegram.Bot.Examples.WebHook as a basis.
I configured the IIS server so that it is always active, configured certificates and everything necessary. The bot started working and receiving messages.
And everything seems to be in order!
The bot receives messages throughout the day, but constantly stops receiving messages.
Sometimes after 2 hours, sometimes after 12 hours, different all the time.
If I stop the server and start it again, the bot starts receiving messages again
Recently he received messages for almost 24 hours, but he stopped receiving messages again.
What could be the reason for these stops specifically when receiving messages?
I followed all the recommendations to configure the IIS server, my test application
guaranteed to work, the bot sends a message every hour and never stops sending,
but receiving messages systematically stops

@InnerCat
Copy link

InnerCat commented Oct 4, 2023

Periodically IIS puts all running applications to sleep and the method StopAsync from ConfigureWebhook is triggered.
Change the method like this and everything should be fine :)

public async Task StopAsync(CancellationToken cancellationToken)
    {
        /*
        using var scope = _serviceProvider.CreateScope();
        var botClient = scope.ServiceProvider.GetRequiredService<ITelegramBotClient>();

        // Remove webhook on app shutdown
        _logger.LogInformation("Removing webhook");
        await botClient.DeleteWebhookAsync(cancellationToken: cancellationToken);
        */
    }

But remember that the webhook for this bot will exist until you stop it or start a new one with a different URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants