added more exception handling

This commit is contained in:
FlorianDahn 2018-08-30 01:44:33 +02:00
parent 7142c8e59f
commit 43fe6533d2
4 changed files with 55 additions and 11 deletions

View File

@ -85,6 +85,10 @@ namespace TelegramBotBase
try
{
Client_TryMessage(sender, e);
}
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
{
}
catch (Exception ex)
{

View File

@ -95,9 +95,23 @@ namespace TelegramBotBase.Sessions
markup = buttons;
}
var message = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
Message m = null;
OnMessageSent(new MessageSentEventArgs(message.MessageId, message));
try
{
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
}
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
{
return;
}
catch
{
return;
}
OnMessageSent(new MessageSentEventArgs(m.MessageId, m));
}
/// <summary>
@ -107,14 +121,27 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task Send(String text, InlineKeyboardMarkup markup , int replyTo = 0, bool disableNotification = false)
public async Task Send(String text, InlineKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false)
{
if (this.ActiveForm == null)
return;
var message = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
Message m = null;
OnMessageSent(new MessageSentEventArgs(message.MessageId, message));
try
{
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
}
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
{
return;
}
catch
{
return;
}
OnMessageSent(new MessageSentEventArgs(m.MessageId, m));
}
/// <summary>
@ -135,9 +162,22 @@ namespace TelegramBotBase.Sessions
markup = buttons;
}
var message = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
Message m = null;
OnMessageSent(new MessageSentEventArgs(message.MessageId, message));
try
{
m = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
}
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
{
return;
}
catch
{
return;
}
OnMessageSent(new MessageSentEventArgs(m.MessageId, m));
}
/// <summary>
@ -212,7 +252,7 @@ namespace TelegramBotBase.Sessions
markup = buttons;
}
var message = await this.Client.TelegramClient.SendDocumentAsync(this.DeviceId, document, caption, replyMarkup: markup, disableNotification: disableNotification, replyToMessageId: replyTo);
var message = await this.Client.TelegramClient.SendDocumentAsync(this.DeviceId, document, caption, replyMarkup: markup, disableNotification: disableNotification, replyToMessageId: replyTo);
OnMessageSent(new MessageSentEventArgs(message.MessageId, message));
}

View File

@ -50,8 +50,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Telegram.Bot, Version=14.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Telegram.Bot.14.4.0\lib\net45\Telegram.Bot.dll</HintPath>
<Reference Include="Telegram.Bot, Version=14.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\UGI\packages\Telegram.Bot.14.6.0\lib\net45\Telegram.Bot.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>

View File

@ -34,5 +34,5 @@
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net452" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net452" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net452" />
<package id="Telegram.Bot" version="14.4.0" targetFramework="net452" />
<package id="Telegram.Bot" version="14.6.0" targetFramework="net452" />
</packages>