added more exception handling
This commit is contained in:
parent
7142c8e59f
commit
43fe6533d2
@ -85,6 +85,10 @@ namespace TelegramBotBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client_TryMessage(sender, e);
|
Client_TryMessage(sender, e);
|
||||||
|
}
|
||||||
|
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -95,9 +95,23 @@ namespace TelegramBotBase.Sessions
|
|||||||
markup = buttons;
|
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>
|
/// <summary>
|
||||||
@ -107,14 +121,27 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
if (this.ActiveForm == null)
|
||||||
return;
|
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>
|
/// <summary>
|
||||||
@ -135,9 +162,22 @@ namespace TelegramBotBase.Sessions
|
|||||||
markup = buttons;
|
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>
|
/// <summary>
|
||||||
|
|||||||
@ -50,8 +50,8 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Telegram.Bot, Version=14.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Telegram.Bot, Version=14.6.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Telegram.Bot.14.4.0\lib\net45\Telegram.Bot.dll</HintPath>
|
<HintPath>..\..\..\UGI\packages\Telegram.Bot.14.6.0\lib\net45\Telegram.Bot.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -34,5 +34,5 @@
|
|||||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net452" />
|
<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.ReaderWriter" version="4.3.0" targetFramework="net452" />
|
||||||
<package id="System.Xml.XDocument" 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>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user