Skip to content

Commit

Permalink
various minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Jun 28, 2024
1 parent 366bba9 commit 7716bc9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
40 changes: 20 additions & 20 deletions Examples/3/LongPolling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 24 in Examples/3/LongPolling.cs

View workflow job for this annotation

GitHub Actions / Build and upload

The variable 'ex' is declared but never used

Check warning on line 24 in Examples/3/LongPolling.cs

View workflow job for this annotation

GitHub Actions / Build and upload

The variable 'ex' is declared but never used
{
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
}
}
2 changes: 1 addition & 1 deletion src/1/example-bot.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/3/updates/polling.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/3/updates/webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/Migration-Guide-to-Version-21.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7716bc9

Please sign in to comment.