Skip to content

Commit

Permalink
Merge pull request #113 from TelegramBots/develop
Browse files Browse the repository at this point in the history
webhook for ASP.NET 4.x
  • Loading branch information
wiz0u committed Jul 5, 2024
2 parents 9ffeeff + f336c7a commit 39dd33a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/3/updates/webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Your application will receive HTTP POST requests with an Update structure in the

Below, you will find how to configure an **ASP.NET Core Web API** project to make it work with Telegram.Bot, either with Controllers or Minimal APIs

## ASP.NET with Controllers (MVC)
## ASP.NET Core with Controllers (MVC)

First you need to configure your Web App startup code:
- Locate the line `services.AddControllers();` _(in Program.cs or Startup.cs)_
Expand All @@ -33,7 +33,7 @@ public async Task HandleUpdate([FromBody] Update update)

Good, now skip to [SetWebHookAsync](#setwebhookasync) below

## ASP.NET with Minimal APIs
## ASP.NET Core with Minimal APIs

First you need to configure your Web App startup code:
- Locate the line `builder.Build();` _(in Program.cs)_
Expand All @@ -53,6 +53,22 @@ async Task HandleUpdate(Update update)
}
```

Good, now skip to [SetWebHookAsync](#setwebhookasync) below

## Old ASP.NET 4.x support

For older .NET Framework usage, you may use the following code:
```csharp
public async Task<IHttpActionResult> Post()
{
Update update;
using (var body = await Request.Content.ReadAsStreamAsync())
update = System.Text.Json.JsonSerializer.Deserialize<Update>(body, JsonSerializerOptionsProvider.Options);
await HandleUpdate(update);
return Ok();
}
```

## SetWebHookAsync
Your update handler code is ready, now you need to instruct Telegram to send updates to your URL, by running:
```csharp
Expand Down

0 comments on commit 39dd33a

Please sign in to comment.