Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Go back to using a single instance of TelegramBot to try avoid webhoo…
Browse files Browse the repository at this point in the history
…k errors
  • Loading branch information
mehtadone committed Mar 2, 2018
1 parent d697cc4 commit de89c19
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions CryptoGramBot/Services/Telegram/TelegramBot.cs
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CryptoGramBot.Configuration;
using CryptoGramBot.Services.Telegram;
using Microsoft.Extensions.Logging;
using Serilog;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;

Expand All @@ -16,6 +12,7 @@ public class TelegramBot
{
private readonly ILogger<TelegramBot> _log;
private readonly TelegramMessageRecieveService _telegramMessageRecieveService;
private TelegramBotClient _bot;

public TelegramBot(TelegramMessageRecieveService telegramMessageRecieveService, ILogger<TelegramBot> log)
{
Expand All @@ -29,8 +26,7 @@ public async Task SendHtmlMessage(long botChatId, string message, string botToke
{
try
{
var bot = new TelegramBotClient(botToken);
await bot.SendTextMessageAsync(botChatId, message, ParseMode.Html);
await _bot.SendTextMessageAsync(botChatId, message, ParseMode.Html);
}
catch (Exception ex)
{
Expand All @@ -44,9 +40,9 @@ public void StartBot(TelegramConfig config)
try
{
ChatId = config.ChatId;
var bot = new TelegramBotClient(config.BotToken);
_bot = new TelegramBotClient(config.BotToken);
// Start the bot so we can start receiving messages
_telegramMessageRecieveService.StartReceivingMessages(bot);
_telegramMessageRecieveService.StartReceivingMessages(_bot);
}
catch (Exception ex)
{
Expand Down

0 comments on commit de89c19

Please sign in to comment.