Добавлены новые методы отправки сообщений
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BotPages.Core;
|
||||
using System;
|
||||
|
||||
namespace BotPages.Telegram;
|
||||
|
||||
@@ -8,25 +9,28 @@ namespace BotPages.Telegram;
|
||||
public static class BotPagesAppExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление адаптера для телеграмм в <see cref="BotPages.Core.Abstractions.IMessengerAdapterFactory"/>
|
||||
/// Добавление адаптера для Telegram.
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="messengerType"></param>
|
||||
/// <returns></returns>
|
||||
public static BotPagesApp AddTelegramAdapter(this BotPagesApp app, string token, string messengerType = "")
|
||||
=> app.AddTelegramAdapter(token, null, messengerType);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление адаптера для телеграмм с опциями.
|
||||
/// </summary>
|
||||
public static BotPagesApp AddTelegramAdapter(this BotPagesApp app, string token, TelegramOptions? options, string messengerType = "")
|
||||
/// <exception cref="ArgumentException">Если адаптер с таким ID уже существует.</exception>
|
||||
public static BotPagesApp AddTelegramAdapter(this BotPagesApp app, string token, string adapterId, TelegramOptions? options = null)
|
||||
{
|
||||
if (app.HasAdapter(adapterId))
|
||||
{
|
||||
throw new ArgumentException($"Adapter with ID '{adapterId}' already exists", nameof(adapterId));
|
||||
}
|
||||
|
||||
var telegram = new TelegramAdapter(app.Logger, token, options);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(messengerType)) telegram.MessengerType = messengerType;
|
||||
|
||||
app.AddAdapter(telegram.MessengerType, telegram);
|
||||
app.AddAdapter(adapterId, telegram);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить Telegram бота с автоматическим ID.
|
||||
/// </summary>
|
||||
public static BotPagesApp AddTelegramAdapter(this BotPagesApp app, string token, TelegramOptions? options = null)
|
||||
{
|
||||
var telegram = new TelegramAdapter(app.Logger, token, options);
|
||||
app.AddAdapter(telegram);
|
||||
return app;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user