Files
BotPages/BotPages.Telegram/BotPagesAppExtension.cs

36 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BotPages.Core;
using System;
namespace BotPages.Telegram;
/// <summary>
/// Расширения для <see cref="BotPagesApp"/>.
/// </summary>
public static class BotPagesAppExtension
{
/// <summary>
/// Добавление адаптера для Telegram.
/// </summary>
/// <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);
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;
}
}