예제 #1
0
 public BotXHttpClient(HttpClient client, BotXConfig config, ILogger <BotXHttpClient> logger)
 {
     this.client = client;
     this.config = config;
     this.logger = logger;
 }
        /// <summary>
        /// Добавляет поддержку BotX Api, позволяя создавать ботов для мессенджера Express
        /// </summary>
        /// <param name="externalServices"></param>
        /// <param name="config">Конфиг для BotX Api</param>
        /// <returns></returns>
        public static ExpressBotService AddExpressBot(this IServiceCollection externalServices, BotXConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (config.BotEntries.Count == 0)
            {
                throw new ArgumentException("Configuration doesn't contain a bot entry. Array must contain at least 1 item");
            }

            externalServices.AddRouting();
            externalServices.AddSingleton(config);

            externalServices.AddHttpClient <IBotXHttpClient, BotXHttpClient>();
            externalServices.AddSingleton(typeof(IBotMessageSender), x => new BotMessageSender(x.GetService <ILogger <BotMessageSender> >(), x.GetService <IBotXHttpClient>()));
            externalServices.AddSingleton <ActionExecutor>();
            externalServices.AddSingleton <MiddlewareExecutor>();
            externalServices.AddSingleton <StateMachineExecutor>();
            ConfigureBotActions(Assembly.GetEntryAssembly(), externalServices);

            return(new ExpressBotService(config.InChatExceptions));
        }