Skip to content

Commit 406ad02

Browse files
committed
Telegram.Bot.Framework moved in the repo
1 parent 0ad19e8 commit 406ad02

26 files changed

+423
-22
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
**/**.csproj.user
77
**/db.sqlite
88
/Examples/Deployf.Botf.ReminderBot/Hangfire.db
9-
**/publish
9+
**/publish
10+
.DS_Store
11+
**/.DS_Store

Deployf.Botf/Attributes/ActionAttribute.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
namespace Deployf.Botf;
1+
using Telegram.Bot.Types.Enums;
2+
3+
namespace Deployf.Botf;
24

35
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
46
public sealed class ActionAttribute : Attribute
57
{
68
public readonly string? Template;
79
public readonly string? Desc;
10+
// public readonly UpdateType[] UpdateTypes;
11+
// public readonly MessageType[] MessageTypes;
812

913
public ActionAttribute(string? template = null, string? desc = null)
1014
{
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
namespace Deployf.Botf;
1+
using Telegram.Bot.Types.Enums;
2+
3+
namespace Deployf.Botf;
24

35
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
46
public sealed class OnAttribute : Attribute
57
{
68
public readonly Handle Handler;
9+
// public readonly UpdateType[] UpdateTypes;
10+
// public readonly MessageType[] MessageTypes;
711

812
public OnAttribute(Handle type)
913
{
1014
Handler = type;
1115
}
12-
}
16+
17+
/*
18+
public OnAttribute(Handle type, params UpdateType[] updateTypes)
19+
{
20+
Handler = type;
21+
UpdateTypes = updateTypes;
22+
}
23+
24+
public OnAttribute(Handle type, params MessageType[] messageTypes)
25+
{
26+
Handler = type;
27+
MessageTypes = messageTypes;
28+
}
29+
30+
public OnAttribute(Handle type, UpdateType[] updateTypes, MessageType[] messageTypes)
31+
{
32+
Handler = type;
33+
MessageTypes = messageTypes;
34+
UpdateTypes = updateTypes;
35+
}
36+
*/
37+
}

Deployf.Botf/BotController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public string FPath(string controller, string action, params object[] args)
540540

541541
#region chaining
542542

543-
public async Task<IUpdateContext> AwaitNextUpdate(Action onCanceled = null)
543+
public async Task<IUpdateContext> AwaitNextUpdate(Action? onCanceled = null)
544544
{
545545
var options = ((BotfBot)Context.Bot).Options;
546546
var store = Context.Services.GetRequiredService<ChainStorage>();
@@ -572,7 +572,7 @@ public async Task<IUpdateContext> AwaitNextUpdate(Action onCanceled = null)
572572
}
573573
}
574574

575-
public async Task<string> AwaitText(Action onCanceled = null)
575+
public async Task<string> AwaitText(Action? onCanceled = null)
576576
{
577577
while (true)
578578
{
@@ -586,7 +586,7 @@ public async Task<string> AwaitText(Action onCanceled = null)
586586
}
587587
}
588588

589-
public async Task<string> AwaitQuery(Action onCanceled = null)
589+
public async Task<string> AwaitQuery(Action? onCanceled = null)
590590
{
591591
while (true)
592592
{

Deployf.Botf/BotfProgram.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static void StartBot(
77
bool skipHello = false,
88
Action<IServiceCollection, IConfiguration>? onConfigure = null,
99
Action<IApplicationBuilder, IConfiguration>? onRun = null,
10-
BotfOptions options = null)
10+
BotfOptions? options = null)
1111
{
1212
if (!skipHello)
1313
{
@@ -27,15 +27,22 @@ public static void StartBot(
2727

2828
if(botOptions == null && builder.Configuration["bot"] != null)
2929
{
30-
//TODO: check the bot section, it should be an object
31-
botOptions = builder.Configuration.GetSection("bot").Get<BotfOptions>();
30+
var section = builder.Configuration.GetSection("bot");
31+
botOptions = section.Get<BotfOptions>();
3232
}
3333

3434
var connectionString = builder.Configuration["botf"];
3535
if (botOptions == null && connectionString != null)
3636
{
3737
botOptions = ConnectionString.Parse(connectionString);
3838
}
39+
40+
if(botOptions == null)
41+
{
42+
throw new BotfException("Configuration is not passed. Check the appsettings*.json.\n" +
43+
"There must be configuration object like `{ \"bot\": { \"Token\": \"BotToken...\" } }`\n" +
44+
"Or connection string(in root) like `{ \"botf\": \"bot_token?key=value\" }`");
45+
}
3946

4047
builder.Services.AddBotf(botOptions);
4148
builder.Services.AddHttpClient();

Deployf.Botf/Deployf.Botf.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
<ItemGroup>
2929
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
30-
<PackageReference Include="Telegram.Bot.Framework" Version="2.0.0-alpha5" />
3130
</ItemGroup>
3231

3332
<ItemGroup>

Deployf.Botf/Messages/MessageBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class MessageBuilder
99
public long ChatId { get; private set; }
1010
public StringBuilder BufferedMessage { get; private set; } = new StringBuilder();
1111
public IReplyMarkup? Markup { get; set; }
12-
public string PhotoUrl { get; set; }
12+
public string? PhotoUrl { get; set; }
1313
public List<List<InlineKeyboardButton>>? Reply { get; set; }
1414
public List<List<KeyboardButton>>? Keyboard { get; set; }
1515
public int ReplyToMessageId { get; set; } = 0;

Deployf.Botf/StartupExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ internal static IApplicationBuilder UseWebhook(this IApplicationBuilder app, IBo
217217
app.Map((PathString)conf.WebhookPath, builder =>
218218
{
219219
var type = Type.GetType("Telegram.Bot.Framework.TelegramBotMiddleware`1[Deployf.Botf.BotfBot], Telegram.Bot.Framework");
220-
builder.UseMiddleware(type, new [] { updateDelegate });
220+
builder.UseMiddleware(type!, new [] { updateDelegate });
221221
});
222222
return app;
223223
}

Deployf.Botf/System/BotfBot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class BotfBot : BotBase
88
public readonly BotfOptions Options;
99

1010
public BotfBot(BotfOptions options)
11-
: base(options.Username, new TelegramBotClient(new TelegramBotClientOptions(options.Token!, baseUrl: options.ApiBaseUrl)))
11+
: base(options.Username!, new TelegramBotClient(new TelegramBotClientOptions(options.Token!, baseUrl: options.ApiBaseUrl)))
1212
{
1313
Options = options;
1414
}

Deployf.Botf/System/BotfOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public string? Username
1818
public string? WebhookUrl { get; set; }
1919
public bool AutoSend { get; set; } = true;
2020
public bool HandleOnlyMentionedInGroups { get; set; }
21-
public string ApiBaseUrl { get; set; }
21+
public string? ApiBaseUrl { get; set; }
2222
public bool AutoCleanReplyKeyboard { get; set; }
2323
public TimeSpan? ChainTimeout { get; set; } = TimeSpan.FromHours(1);
2424
public bool UseWebhooks => !string.IsNullOrEmpty(WebhookUrl);

0 commit comments

Comments
 (0)