Skip to content

Commit

Permalink
onupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomatossilva committed Oct 19, 2019
1 parent ba80651 commit 116c5e4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions WebApplication3/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -9,6 +10,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types.Enums;

namespace WebApplication3
{
Expand All @@ -17,9 +21,21 @@ public class Startup
public Startup(IConfiguration configuration)
{
Configuration = configuration;
BotClient = new TelegramBotClient(Configuration.GetValue<string>("TelegramToken"), new HttpClient());
BotClient.OnUpdate += BotClientOnOnUpdate;
BotClient.StartReceiving(allowedUpdates: new []{UpdateType.Message, UpdateType.ChannelPost});
}

private async void BotClientOnOnUpdate(object sender, UpdateEventArgs e)
{
await BotClient.SendTextMessageAsync(
chatId: e.Update.Message.Chat,
text: "You said:\n" + e.Update.Message.Text
);
}

public IConfiguration Configuration { get; }
public TelegramBotClient BotClient { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand Down

0 comments on commit 116c5e4

Please sign in to comment.