From 7716bc9a6e76d3dba0be9b4efc0ca9f8580af589 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Fri, 28 Jun 2024 23:42:30 +0200 Subject: [PATCH] various minor fixes --- Examples/3/LongPolling.cs | 40 +++++++++++++------------- src/1/example-bot.md | 2 +- src/3/updates/polling.md | 2 +- src/3/updates/webhook.md | 6 ++-- src/Migration-Guide-to-Version-21.x.md | 4 +-- src/SUMMARY.md | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Examples/3/LongPolling.cs b/Examples/3/LongPolling.cs index 588e7d2..17a9817 100644 --- a/Examples/3/LongPolling.cs +++ b/Examples/3/LongPolling.cs @@ -6,28 +6,28 @@ internal class ExampleBot { private async Task LongPolling() { - // ANCHOR: long-polling - CancellationTokenSource cts = new(); - var bot = new TelegramBotClient("{YOUR BOT TOKEN HERE}", cancellationToken: cts.Token); +// ANCHOR: long-polling +CancellationTokenSource cts = new(); +var bot = new TelegramBotClient("{YOUR BOT TOKEN HERE}", cancellationToken: cts.Token); - int? offset = null; - while (!cts.IsCancellationRequested) +int? offset = null; +while (!cts.IsCancellationRequested) +{ + var updates = await bot.GetUpdatesAsync(offset, timeout: 2); + foreach (var update in updates) + { + offset = update.Id + 1; + try + { + // put your code to handle one Update here. + } + catch (Exception ex) { - var updates = await bot.GetUpdatesAsync(offset, timeout: 2); - foreach (var update in updates) - { - offset = update.Id + 1; - try - { - // put your code to handle one Update here. - } - catch (Exception ex) - { - // log exception and continue - } - if (cts.IsCancellationRequested) break; - } + // log exception and continue } - // ANCHOR_END: long-polling + if (cts.IsCancellationRequested) break; + } +} +// ANCHOR_END: long-polling } } diff --git a/src/1/example-bot.md b/src/1/example-bot.md index 017ee67..60573fc 100644 --- a/src/1/example-bot.md +++ b/src/1/example-bot.md @@ -1,4 +1,4 @@ -# Example - First Chat Bot +# Full Example - Your first bot On the [previous page] we got an access token and used the [`getMe`] method to check our setup. Now, it is time to make an _interactive_ bot that gets users' messages and replies to them like in this screenshot: diff --git a/src/3/updates/polling.md b/src/3/updates/polling.md index 340dfde..240b890 100644 --- a/src/3/updates/polling.md +++ b/src/3/updates/polling.md @@ -1,6 +1,6 @@ # Long Polling -If you don't want to use our recommended StartReceiving helper ([see first example](../1/example-bot.md)), +If you don't want to use our recommended **StartReceiving** helper ([see first example](../../1/example-bot.md)), you can just call GetUpdateAsync with a timeout in a loop, such that the call blocks for **up to** X seconds until there is an incoming update diff --git a/src/3/updates/webhook.md b/src/3/updates/webhook.md index a78f61b..1c9a1ec 100644 --- a/src/3/updates/webhook.md +++ b/src/3/updates/webhook.md @@ -13,7 +13,7 @@ Below, you will find how to configure an **ASP.NET Core Web API** project to mak First you need to configure your Web App startup code: - Locate the line `services.AddControllers();` _(in Program.cs or Startup.cs)_ -- If you're under .NET 6.0 or more recent, add the line: +- If you're using .NET 6.0 or more recent, add the line: ```csharp services.ConfigureTelegramBotMvc(); ``` @@ -66,9 +66,9 @@ You can now deploy your app to your webapp host machine. - You need a supported certificate If your host doesn't provide one or you want to develop on your own machine, consider using [ngrok](https://ngrok.com/): -https://medium.com/@oktaykopcak/81c8c4a9a853 +Useful [step-by-step guide](https://medium.com/@oktaykopcak/81c8c4a9a853) - You must use HTTPS (TLS 1.2+), IPv4, and ports 443, 80, 88, or 8443 -- Full webhook guide: https://core.telegram.org/bots/webhooks +- [Official webhook guide](https://core.telegram.org/bots/webhooks) - If your update handler throws an exception or takes too much time to return, Telegram will consider it a temporary failure and will RESEND the same update a bit later. So you may want to prevent handling the same update.Id twice: diff --git a/src/Migration-Guide-to-Version-21.x.md b/src/Migration-Guide-to-Version-21.x.md index ca08266..747f638 100644 --- a/src/Migration-Guide-to-Version-21.x.md +++ b/src/Migration-Guide-to-Version-21.x.md @@ -80,9 +80,9 @@ To make a payment in [Telegram Stars](https://t.me/BotNews/90) with SendInvoiceA The library now uses `System.Text.Json` instead of `NewtonsoftJson`. -To make it work in your ASP.NET projects, you'll need to: +To make it work in your ASP.NET projects, you should now: - Remove package **Microsoft.AspNetCore.Mvc.NewtonsoftJson** from your project dependencies -- Configure your webapp. See our [Webhook page](3/updates/webhook.md) +- Follow our [Webhook page](3/updates/webhook.md) to configure your web app correctly ## InputPollOption in SendPollAsync diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 96a8aa3..2849c3c 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -2,7 +2,7 @@ - [Introduction](README.md) - [Quickstart](1/quickstart.md) - - [Example - First Chat Bot](1/example-bot.md) + - [Full Example](1/example-bot.md) - [Beginner](2/README.md) - [Sending Messages](2/send-msg/README.md) - [Text](2/send-msg/text-msg.md)