Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82e6d79ec4 | ||
|
|
5d2f3e7fe9 | ||
|
|
7aa40b3e2d | ||
|
|
eb8fad444b | ||
|
|
5cda9e1fdc | ||
|
|
41bdf52afe | ||
|
|
9023875922 | ||
|
|
05bfeb8d09 | ||
|
|
1f1aa1f0ee | ||
|
|
3d97da75f1 | ||
|
|
261fdafd96 | ||
|
|
39e68a2089 | ||
|
|
312690c002 | ||
|
|
99b888a7a2 | ||
|
|
6adcc52ea2 | ||
|
|
834038ff44 | ||
|
|
e3d1652a02 | ||
|
|
a7411176e6 | ||
|
|
801c0b77f8 | ||
|
|
7a86ecdf32 | ||
|
|
175927fbab | ||
|
|
34e4429b38 | ||
|
|
dc28bde382 | ||
|
|
87d57c471a | ||
|
|
5ce2360cc7 | ||
|
|
e345fc2948 | ||
|
|
652526ec59 | ||
|
|
b829f43c5d | ||
|
|
6e7acdbdba | ||
|
|
396a524d94 | ||
|
|
7d679649e4 |
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TelegramBotBase" Version="5.3.0" />
|
||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace BotAndWebApplication.BotStuff.Tasks
|
||||
.DefaultCommands()
|
||||
.NoSerialization()
|
||||
.UseEnglish()
|
||||
.UseThreadPool()
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
||||
|
||||
**Need your own bot? Get in touch https://t.me/botbasebuilder**
|
||||
|
||||
**on X: @florian_zevedei**
|
||||
|
||||
## Donate
|
||||
|
||||
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
||||
@@ -102,6 +106,7 @@ var bot = BotBaseBuilder
|
||||
})
|
||||
.NoSerialization()
|
||||
.UseEnglish()
|
||||
.UseSingleThread()
|
||||
.Build();
|
||||
|
||||
// Upload bot commands to BotFather
|
||||
@@ -122,8 +127,32 @@ like ChatId and other stuff your carrying.
|
||||
From there you build up your bots:
|
||||
|
||||
```csharp
|
||||
public class StartForm : FormBase
|
||||
public class Start : FormBase
|
||||
{
|
||||
|
||||
public Start()
|
||||
{
|
||||
//Additional event handlers
|
||||
Init += Start_Init;
|
||||
Opened += Start_Opened;
|
||||
Closed += Start_Closed;
|
||||
}
|
||||
|
||||
// Gets invoked on initialization, before navigation
|
||||
private async Task Start_Init(object sender, Args.InitEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Gets invoked after opened
|
||||
private async Task Start_Opened(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Gets invoked after form has been closed
|
||||
private async Task Start_Closed(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Gets invoked during Navigation to this form
|
||||
public override async Task PreLoad(MessageResult message)
|
||||
{
|
||||
@@ -220,6 +249,7 @@ var bot = BotBaseBuilder
|
||||
})
|
||||
.NoSerialization()
|
||||
.UseEnglish()
|
||||
.UseSingleThread()
|
||||
.Build();
|
||||
|
||||
bot.BotCommand += async (s, en) =>
|
||||
@@ -260,15 +290,15 @@ public class SimpleForm : AutoCleanForm
|
||||
{
|
||||
public SimpleForm()
|
||||
{
|
||||
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
|
||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
||||
DeleteSide = EDeleteSide.Both;
|
||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||
|
||||
this.Opened += SimpleForm_Opened;
|
||||
Opened += SimpleForm_Opened;
|
||||
}
|
||||
|
||||
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
||||
{
|
||||
await this.Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
||||
await Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
@@ -306,7 +336,13 @@ public class SimpleForm : AutoCleanForm
|
||||
```csharp
|
||||
public class ButtonTestForm : AutoCleanForm
|
||||
{
|
||||
public override async Task Opened()
|
||||
public ButtonTestForm()
|
||||
{
|
||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
||||
Opened += ButtonTestForm_Opened;
|
||||
}
|
||||
|
||||
private async Task ButtonTestForm_Opened(object sender, EventArgs e)
|
||||
{
|
||||
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
||||
}
|
||||
@@ -376,9 +412,10 @@ public class ProgressTest : AutoCleanForm
|
||||
public ProgressTest()
|
||||
{
|
||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
||||
Opened += ProgressTest_Opened;
|
||||
}
|
||||
|
||||
public override async Task Opened()
|
||||
private async Task ProgressTest_Opened(object sender, EventArgs e)
|
||||
{
|
||||
await this.Device.Send("Welcome to ProgressTest");
|
||||
}
|
||||
@@ -858,6 +895,7 @@ var bot = BotBaseBuilder
|
||||
})
|
||||
.UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||
.UseEnglish()
|
||||
.UseSingleThread()
|
||||
.Build();
|
||||
|
||||
await bot.Start();
|
||||
@@ -881,6 +919,7 @@ var bot = BotBaseBuilder
|
||||
})
|
||||
.UseJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||
.UseEnglish()
|
||||
.UseSingleThread()
|
||||
.Build();
|
||||
|
||||
await bot.Start();
|
||||
@@ -903,6 +942,7 @@ var bot = BotBaseBuilder
|
||||
})
|
||||
.UseXML(AppContext.BaseDirectory + "config\\states.xml")
|
||||
.UseEnglish()
|
||||
.UseSingleThread()
|
||||
.Build();
|
||||
|
||||
await bot.Start();
|
||||
@@ -916,7 +956,7 @@ datatype and one for implementing into a form which should be invoked with event
|
||||
#### IStateMachine
|
||||
|
||||
Is the basic StateMachine interface, it has two methods `SaveFormStates(SaveStatesEventArgs e)`
|
||||
and `StateContainerLoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
||||
and `LoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
||||
serialization process.
|
||||
|
||||
```csharp
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.1.1" />
|
||||
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.5.1" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
@@ -9,16 +10,36 @@ namespace TelegramBotBase.Base;
|
||||
|
||||
public class MessageResult : ResultBase
|
||||
{
|
||||
internal MessageResult()
|
||||
{
|
||||
}
|
||||
|
||||
public MessageResult(Update update)
|
||||
{
|
||||
UpdateData = update;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public Update UpdateData { get; set; }
|
||||
void init()
|
||||
{
|
||||
IsAction = UpdateData.CallbackQuery != null;
|
||||
|
||||
if (Message == null)
|
||||
return;
|
||||
|
||||
IsBotCommand = Message.Entities?.Any(a => a.Type == MessageEntityType.BotCommand) ?? false;
|
||||
|
||||
if (!IsBotCommand)
|
||||
return;
|
||||
|
||||
BotCommand = MessageText.Split(' ')[0];
|
||||
|
||||
IsBotGroupCommand = BotCommand.Contains("@");
|
||||
|
||||
if (IsBotGroupCommand)
|
||||
{
|
||||
BotCommand = BotCommand.Substring(0, BotCommand.LastIndexOf('@'));
|
||||
}
|
||||
}
|
||||
|
||||
public Update UpdateData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Device/ChatId
|
||||
@@ -55,12 +76,17 @@ public class MessageResult : ResultBase
|
||||
/// <summary>
|
||||
/// Is this an action ? (i.e. button click)
|
||||
/// </summary>
|
||||
public bool IsAction => UpdateData.CallbackQuery != null;
|
||||
public bool IsAction { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is this a command ? Starts with a slash '/' and a command
|
||||
/// </summary>
|
||||
public bool IsBotCommand => MessageText.StartsWith("/");
|
||||
public bool IsBotCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is this a bot command sent from a group via @BotId ?
|
||||
/// </summary>
|
||||
public bool IsBotGroupCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
||||
@@ -83,18 +109,7 @@ public class MessageResult : ResultBase
|
||||
/// <summary>
|
||||
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
||||
/// </summary>
|
||||
public string BotCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsBotCommand)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return MessageText.Split(' ')[0];
|
||||
}
|
||||
}
|
||||
public string BotCommand { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns if this message will be used on the first form or not.
|
||||
|
||||
@@ -8,6 +8,7 @@ using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Sessions;
|
||||
using Console = TelegramBotBase.Tools.Console;
|
||||
@@ -115,7 +116,7 @@ public sealed class BotBase
|
||||
if (ds == null)
|
||||
{
|
||||
ds = await Sessions.StartSession(e.DeviceId);
|
||||
ds.LastMessage = e.RawData.Message;
|
||||
ds.LastMessage = e.Message;
|
||||
|
||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||
}
|
||||
@@ -139,6 +140,13 @@ public sealed class BotBase
|
||||
mr.IsFirstHandler = false;
|
||||
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
||||
}
|
||||
catch (InvalidServiceProviderConfiguration ex)
|
||||
{
|
||||
var ds = Sessions.GetSession(e.DeviceId);
|
||||
OnException(new SystemExceptionEventArgs(e.Message.Text, e.DeviceId, ds, ex));
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var ds = Sessions.GetSession(e.DeviceId);
|
||||
@@ -189,13 +197,10 @@ public sealed class BotBase
|
||||
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
||||
public async Task InvokeMessageLoop(long deviceId)
|
||||
{
|
||||
var mr = new MessageResult
|
||||
{
|
||||
UpdateData = new Update
|
||||
var mr = new MessageResult(new Update
|
||||
{
|
||||
Message = new Message()
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
await InvokeMessageLoop(deviceId, mr);
|
||||
}
|
||||
@@ -260,7 +265,7 @@ public sealed class BotBase
|
||||
{
|
||||
foreach (var scope in BotCommandScopes)
|
||||
{
|
||||
if (scope.Value.Any(a => "/" + a.Command == command))
|
||||
if (scope.Value.Any(a => Constants.Telegram.BotCommandIndicator + a.Command == command))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -73,14 +73,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage QuickStart(string apiKey, Type startForm)
|
||||
public IBuildingStage QuickStart(string apiKey, Type startForm, bool throwPendingUpdates = false)
|
||||
{
|
||||
_apiKey = apiKey;
|
||||
_factory = new DefaultStartFormFactory(startForm);
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
NoProxy(throwPendingUpdates);
|
||||
|
||||
OnlyStart();
|
||||
|
||||
@@ -94,7 +94,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage QuickStart<T>(string apiKey)
|
||||
public IBuildingStage QuickStart<T>(string apiKey, bool throwPendingUpdates = false)
|
||||
where T : FormBase
|
||||
{
|
||||
_apiKey = apiKey;
|
||||
@@ -102,7 +102,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
NoProxy(throwPendingUpdates);
|
||||
|
||||
OnlyStart();
|
||||
|
||||
@@ -115,14 +115,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory)
|
||||
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory, bool throwPendingUpdates = false)
|
||||
{
|
||||
_apiKey = apiKey;
|
||||
_factory = startFormFactory;
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
NoProxy(throwPendingUpdates);
|
||||
|
||||
OnlyStart();
|
||||
|
||||
@@ -399,41 +399,41 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
||||
#region "Step 7 (Language)"
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.DefaultLanguage"/>
|
||||
public IBuildingStage DefaultLanguage()
|
||||
public IThreadingStage DefaultLanguage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.UseEnglish"/>
|
||||
public IBuildingStage UseEnglish()
|
||||
public IThreadingStage UseEnglish()
|
||||
{
|
||||
Default.Language = new English();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.UseGerman"/>
|
||||
public IBuildingStage UseGerman()
|
||||
public IThreadingStage UseGerman()
|
||||
{
|
||||
Default.Language = new German();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.UsePersian"/>
|
||||
public IBuildingStage UsePersian()
|
||||
public IThreadingStage UsePersian()
|
||||
{
|
||||
Default.Language = new Persian();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.UseRussian"/>
|
||||
public IBuildingStage UseRussian()
|
||||
public IThreadingStage UseRussian()
|
||||
{
|
||||
Default.Language = new Russian();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ILanguageSelectionStage.Custom"/>
|
||||
public IBuildingStage Custom(Localization language)
|
||||
public IThreadingStage Custom(Localization language)
|
||||
{
|
||||
Default.Language = language;
|
||||
return this;
|
||||
|
||||
@@ -20,16 +20,18 @@ public interface IAPIKeySelectionStage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="StartForm"></param>
|
||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart(string apiKey, Type StartForm);
|
||||
IBuildingStage QuickStart(string apiKey, Type StartForm, bool throwPendingUpdates = false);
|
||||
|
||||
/// <summary>
|
||||
/// Quick and easy way to create a BotBase instance.
|
||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart<T>(string apiKey) where T : FormBase;
|
||||
IBuildingStage QuickStart<T>(string apiKey , bool throwPendingUpdates = false) where T : FormBase;
|
||||
|
||||
/// <summary>
|
||||
/// Quick and easy way to create a BotBase instance.
|
||||
@@ -37,6 +39,7 @@ public interface IAPIKeySelectionStage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="StartFormFactory"></param>
|
||||
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory);
|
||||
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory, bool throwPendingUpdates = false);
|
||||
}
|
||||
@@ -11,35 +11,35 @@ public interface ILanguageSelectionStage
|
||||
/// Selects the default language for control usage. (English)
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage DefaultLanguage();
|
||||
IThreadingStage DefaultLanguage();
|
||||
|
||||
/// <summary>
|
||||
/// Selects english as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage UseEnglish();
|
||||
IThreadingStage UseEnglish();
|
||||
|
||||
/// <summary>
|
||||
/// Selects german as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage UseGerman();
|
||||
IThreadingStage UseGerman();
|
||||
|
||||
/// <summary>
|
||||
/// Selects persian as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage UsePersian();
|
||||
IThreadingStage UsePersian();
|
||||
|
||||
/// <summary>
|
||||
/// Selects russian as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage UseRussian();
|
||||
IThreadingStage UseRussian();
|
||||
|
||||
/// <summary>
|
||||
/// Selects a custom language as the default language for control labels.
|
||||
/// </summary>
|
||||
/// <returns>The next stage in the building process.</returns>
|
||||
IBuildingStage Custom(Localization language);
|
||||
IThreadingStage Custom(Localization language);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
@@ -20,6 +21,16 @@ public static class Extensions
|
||||
scope = BotCommandScope.Default();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(command))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(command), $"{nameof(command)} parameter can not be null or empty");
|
||||
}
|
||||
|
||||
if(command.StartsWith(Constants.Telegram.BotCommandIndicator))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(command)} parameter does not have to start with a slash, please remove.", $"{nameof(command)}");
|
||||
}
|
||||
|
||||
var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type);
|
||||
|
||||
if (item.Value != null)
|
||||
|
||||
@@ -16,4 +16,15 @@ public static class Telegram
|
||||
public const int MaxReplyKeyboardCols = 12;
|
||||
|
||||
public const int MessageDeletionsPerSecond = 30;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum length of callback data. Will raise an exception of it exceeds it.
|
||||
/// </summary>
|
||||
public const int MaxCallBackDataBytes = 64;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The slash constant which indicates a bot command.
|
||||
/// </summary>
|
||||
public const string BotCommandIndicator = "/";
|
||||
}
|
||||
@@ -51,7 +51,24 @@ public class ButtonGrid : ControlBase
|
||||
DataSource = new ButtonFormDataSource(form);
|
||||
}
|
||||
|
||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Title;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
m_Title = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ConfirmationText { get; set; } = "";
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Localizations;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using static TelegramBotBase.Base.Async;
|
||||
|
||||
namespace TelegramBotBase.Controls.Hybrid;
|
||||
@@ -51,7 +52,24 @@ public class CheckedButtonList : ControlBase
|
||||
DataSource = new ButtonFormDataSource(form);
|
||||
}
|
||||
|
||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Title;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
m_Title = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ConfirmationText { get; set; } = "";
|
||||
|
||||
|
||||
@@ -67,7 +67,24 @@ public class TaggedButtonGrid : MultiView
|
||||
DataSource = new ButtonFormDataSource(form);
|
||||
}
|
||||
|
||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
||||
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Title;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
m_Title = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ConfirmationText { get; set; }
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Label : ControlBase
|
||||
{
|
||||
private bool _renderNecessary = true;
|
||||
|
||||
private string _text = string.Empty;
|
||||
private string _text = Default.Language["Label_Text"];
|
||||
|
||||
public String Text
|
||||
{
|
||||
@@ -29,6 +29,10 @@ public class Label : ControlBase
|
||||
if (_text == value)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Text)}", $"{nameof(Text)} property must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
_text = value;
|
||||
_renderNecessary = true;
|
||||
@@ -36,6 +40,8 @@ public class Label : ControlBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ParseMode _parseMode = ParseMode.Markdown;
|
||||
|
||||
public ParseMode ParseMode
|
||||
|
||||
@@ -32,10 +32,32 @@ public class MultiToggleButton : ControlBase
|
||||
/// </summary>
|
||||
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
|
||||
|
||||
private string _title = Default.Language["MultiToggleButton_Title"];
|
||||
|
||||
/// <summary>
|
||||
/// This holds the title of the control.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = Default.Language["MultiToggleButton_Title"];
|
||||
public String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_title == value)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
_title = value;
|
||||
_renderNecessary = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int? MessageId { get; set; }
|
||||
|
||||
|
||||
@@ -36,7 +36,31 @@ public class ToggleButton : ControlBase
|
||||
|
||||
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
|
||||
|
||||
public string Title { get; set; } = Default.Language["ToggleButton_Title"];
|
||||
private string _title = Default.Language["ToggleButton_Title"];
|
||||
|
||||
public String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_title == value)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||
}
|
||||
|
||||
_title = value;
|
||||
_renderNecessary = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int? MessageId { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Telegram.Bot.Exceptions;
|
||||
|
||||
namespace TelegramBotBase.Exceptions;
|
||||
|
||||
public sealed class CallbackDataTooLongException : Exception
|
||||
{
|
||||
static ApiRequestException _innerException = new Telegram.Bot.Exceptions.ApiRequestException("Bad Request: BUTTON_DATA_INVALID", 400);
|
||||
|
||||
static String _message = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
||||
|
||||
static String _message_with_bytes = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data with @current_callback_bytes@ bytes.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
||||
|
||||
public CallbackDataTooLongException() : base(_message, _innerException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="current_callback_bytes">The amount of callback bytes generated.</param>
|
||||
public CallbackDataTooLongException(int current_callback_bytes) : base(getMessage(current_callback_bytes), _innerException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static String getMessage(int current_callback_bytes = -1)
|
||||
{
|
||||
if (current_callback_bytes == -1)
|
||||
return _message;
|
||||
|
||||
return _message_with_bytes.Replace("@current_callback_bytes@", current_callback_bytes.ToString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace TelegramBotBase.Exceptions
|
||||
{
|
||||
public sealed class InvalidServiceProviderConfiguration : Exception
|
||||
{
|
||||
public InvalidServiceProviderConfiguration(string message, Exception innerException) : base(message, innerException) { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TelegramBotBase.DependencyInjection;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
@@ -24,7 +25,16 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
||||
|
||||
public FormBase CreateForm()
|
||||
{
|
||||
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
FormBase fb = null;
|
||||
|
||||
try
|
||||
{
|
||||
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||
}
|
||||
catch(InvalidOperationException ex)
|
||||
{
|
||||
throw new InvalidServiceProviderConfiguration(ex.Message, ex);
|
||||
}
|
||||
|
||||
//Sets an internal field for future ServiceProvider navigation
|
||||
fb.SetServiceProvider(_serviceProvider);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Exceptions;
|
||||
|
||||
namespace TelegramBotBase.Form;
|
||||
|
||||
@@ -23,22 +25,24 @@ public class CallbackData
|
||||
|
||||
public static string Create(string method, string value)
|
||||
{
|
||||
return new CallbackData(method, value).Serialize();
|
||||
return new CallbackData(method, value).Serialize(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes data to json string
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Serialize()
|
||||
{
|
||||
var s = "";
|
||||
try
|
||||
public string Serialize(bool throwExceptionOnOverflow = false)
|
||||
{
|
||||
var s = string.Empty;
|
||||
|
||||
s = JsonConvert.SerializeObject(this);
|
||||
}
|
||||
catch
|
||||
|
||||
//Is data over 64 bytes ?
|
||||
int byte_count = Encoding.UTF8.GetByteCount(s);
|
||||
if (throwExceptionOnOverflow && byte_count > Constants.Telegram.MaxCallBackDataBytes)
|
||||
{
|
||||
throw new CallbackDataTooLongException(byte_count);
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -51,19 +55,8 @@ public class CallbackData
|
||||
/// <returns></returns>
|
||||
public static CallbackData Deserialize(string data)
|
||||
{
|
||||
CallbackData cd = null;
|
||||
try
|
||||
{
|
||||
cd = JsonConvert.DeserializeObject<CallbackData>(data);
|
||||
|
||||
return cd;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return JsonConvert.DeserializeObject<CallbackData>(data);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize();
|
||||
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
|
||||
}
|
||||
|
||||
@@ -34,5 +34,6 @@ public sealed class English : Localization
|
||||
Values["ToggleButton_Changed"] = "Setting changed";
|
||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||
Values["Label_Text"] = "Default label text";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,5 +34,6 @@ public sealed class German : Localization
|
||||
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||
Values["Label_Text"] = "Standard Label Text";
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public sealed class Persian : Localization
|
||||
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||
Values["Label_Text"] = "متن برچسب پیشفرض";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,5 +34,6 @@ public sealed class Russian : Localization
|
||||
Values["ToggleButton_Changed"] = "Настройки изменены";
|
||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||
Values["Label_Text"] = "Текст метки по умолчанию";
|
||||
}
|
||||
}
|
||||
@@ -79,13 +79,16 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
||||
}
|
||||
|
||||
//Action Event
|
||||
if (!session.FormSwitched && mr.IsAction)
|
||||
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
||||
{
|
||||
//Send Action event to controls
|
||||
await activeForm.ActionControls(mr);
|
||||
|
||||
//Send Action event to form itself
|
||||
if (!mr.Handled)
|
||||
{
|
||||
//Send Action event to form itself, if not already handled by a control
|
||||
await activeForm.Action(mr);
|
||||
}
|
||||
|
||||
if (!mr.Handled)
|
||||
{
|
||||
|
||||
@@ -72,13 +72,16 @@ public class FullMessageLoop : IMessageLoopFactory
|
||||
}
|
||||
|
||||
//Action Event
|
||||
if (!session.FormSwitched && mr.IsAction)
|
||||
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
||||
{
|
||||
//Send Action event to controls
|
||||
await activeForm.ActionControls(mr);
|
||||
|
||||
//Send Action event to form itself
|
||||
if (!mr.Handled)
|
||||
{
|
||||
//Send Action event to form itself, if not already handled by a control
|
||||
await activeForm.Action(mr);
|
||||
}
|
||||
|
||||
if (!mr.Handled)
|
||||
{
|
||||
|
||||
@@ -131,13 +131,9 @@ public class DeviceSession : IDeviceSession
|
||||
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
|
||||
string urlToOpen = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -157,17 +153,8 @@ public class DeviceSession : IDeviceSession
|
||||
throw new MessageTooLongException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await Api(a =>
|
||||
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -185,17 +172,9 @@ public class DeviceSession : IDeviceSession
|
||||
throw new MessageTooLongException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await Api(a =>
|
||||
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -215,19 +194,9 @@ public class DeviceSession : IDeviceSession
|
||||
throw new MessageTooLongException(message.Text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await Api(a =>
|
||||
a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
||||
return await Api(a => a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
||||
replyMarkup: markup));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edits the reply keyboard markup (buttons)
|
||||
@@ -237,15 +206,8 @@ public class DeviceSession : IDeviceSession
|
||||
/// <returns></returns>
|
||||
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -277,8 +239,7 @@ public class DeviceSession : IDeviceSession
|
||||
text = text.MarkdownV2Escape();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||
replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
@@ -287,11 +248,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -336,8 +293,7 @@ public class DeviceSession : IDeviceSession
|
||||
text = text.MarkdownV2Escape();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||
replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
@@ -345,11 +301,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -379,8 +331,7 @@ public class DeviceSession : IDeviceSession
|
||||
text = text.MarkdownV2Escape();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||
replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
@@ -388,11 +339,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -414,8 +361,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
||||
replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
@@ -423,11 +369,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -449,8 +391,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
||||
replyToMessageId: replyTo, replyMarkup: markup,
|
||||
disableNotification: disableNotification));
|
||||
@@ -459,11 +400,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -484,8 +421,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
||||
replyToMessageId: replyTo, replyMarkup: markup,
|
||||
disableNotification: disableNotification));
|
||||
@@ -494,11 +430,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -520,8 +452,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var ms = new MemoryStream(video);
|
||||
|
||||
var fts = InputFile.FromStream(ms, filename);
|
||||
@@ -533,11 +464,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -560,8 +487,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var fs = new FileStream(filepath, FileMode.Open);
|
||||
|
||||
var filename = Path.GetFileName(filepath);
|
||||
@@ -575,11 +501,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -650,8 +572,7 @@ public class DeviceSession : IDeviceSession
|
||||
markup = buttons;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
|
||||
disableNotification: disableNotification, replyToMessageId: replyTo));
|
||||
|
||||
@@ -659,11 +580,7 @@ public class DeviceSession : IDeviceSession
|
||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||
|
||||
return await t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -714,8 +631,7 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
||||
|
||||
if (autoDeleteResponse && m != null)
|
||||
@@ -724,12 +640,7 @@ public class DeviceSession : IDeviceSession
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -759,13 +670,9 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Type GetOrigin(StackTrace stackTrace)
|
||||
@@ -878,49 +785,31 @@ public class DeviceSession : IDeviceSession
|
||||
|
||||
public virtual async Task<ChatMember> GetChatUser(long userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
||||
|
||||
}
|
||||
|
||||
[Obsolete("User BanUser instead.")]
|
||||
public virtual async Task KickUser(long userId, DateTime until = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual async Task BanUser(long userId, DateTime until = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual async Task UnbanUser(long userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user