2018-05-22 10:11:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Telegram.Bot;
|
|
|
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
|
2018-12-03 19:45:06 +01:00
|
|
|
|
namespace Core.Helper
|
|
|
|
|
{
|
|
|
|
|
public static class TelegramHelper
|
|
|
|
|
{
|
|
|
|
|
public static void SendMessage(string botToken, Int64 chatId, string message, bool useSilentMode, LogHelper log)
|
|
|
|
|
{
|
|
|
|
|
if (!botToken.Equals("") && chatId != 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
TelegramBotClient botClient = new TelegramBotClient(botToken);
|
|
|
|
|
System.Threading.Tasks.Task<Message> sentMessage = botClient.SendTextMessageAsync(chatId, message, ParseMode.Markdown, false, useSilentMode);
|
|
|
|
|
|
2018-12-03 19:45:06 +01:00
|
|
|
|
if (sentMessage.IsCompleted)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
log.DoLogDebug("Telegram message sent to ChatId " + chatId.ToString() + " on Bot Token '" + botToken + "'");
|
|
|
|
|
}
|
2018-12-03 19:45:06 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
log.DoLogCritical("Exception sending telegram message to ChatId " + chatId.ToString() + " on Bot Token '" + botToken + "'", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|