forked from javiermolinar/ServerlessTelegramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
29 lines (26 loc) · 1.29 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Microsoft.Azure.EventGrid;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Telegram.Bot;
using System;
[assembly: FunctionsStartup(typeof(ServerlessTelegramBot.Startup))]
namespace ServerlessTelegramBot
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
ITelegramBotClient botClient = null;
var eventGridClient = new EventGridClient(new TopicCredentials(Environment.GetEnvironmentVariable("EventGridTopicApiKey")));
botClient = new TelegramBotClient(Environment.GetEnvironmentVariable("TelegramApiKey"));
if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Webhookaddress"))){
botClient.SetWebhookAsync($"{Environment.GetEnvironmentVariable("Webhookaddress")}/api/TelegramBotWebHook/{Environment.GetEnvironmentVariable("WebhookParameters")}").Wait();
}
builder.Services.AddSingleton<ITelegramBotClient>(botClient);
builder.Services.AddSingleton<IEventGridClient>(eventGridClient);
}
}
}