示例#1
0
        /// <summary>
        ///
        /// </summary>
        public virtual void Run()
        {
            var options = TelegramBotConfig.GetOptions(AppConfig.OptionsName);

            if (options == null)
            {
                throw new Exception($"Telegram bot options not configured! Options name: {AppConfig.OptionsName}");
            }

            _container        = options.Container;
            _servicesProvider = options.ServicesProvider;

            options.ServicesRegistrator?.Register(_container, options);
            _container.Initialize();

            var commandFactory = _servicesProvider.GetService <ITelegramBotCommandFactory>();

            commandFactory.Initialize();
            AppConfig.Configure(this);

            var clientManager = _servicesProvider.GetService <ITelegramBotClientManager>();

            clientManager.Token = AppConfig.Token;
            clientManager.Initialize();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="servicesProvider"></param>
 public virtual void Initialize(ITelegramBotServicesProvider servicesProvider)
 {
     ServicesProvider = servicesProvider;
     Client           = ServicesProvider.GetService <ITelegramBotClientManager>().Client;
     UserService      = ServicesProvider.GetService <ITelegramBotUserService>();
     MessageService   = ServicesProvider.GetService <ITelegramBotMessageService>();
     CommandService   = new TelegramBotCommandService(this, ServicesProvider);
 }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        public virtual void Dispose()
        {
            var clientManager = _servicesProvider.GetService <ITelegramBotClientManager>();

            clientManager?.Dispose();
            _container?.Dispose();
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <param name="servicesProvider"></param>
        public TelegramBotCommandService(ITelegramBotCommand command, ITelegramBotServicesProvider servicesProvider)
        {
            Command = command;
            TelegramBotServicesProvider = servicesProvider;
            TelegramBotCommandFactory   = servicesProvider.GetService <ITelegramBotCommandFactory>();

            Info           = TelegramBotCommandFactory.GetCommandInfo(command.GetType());
            MessageService = TelegramBotServicesProvider.GetService <ITelegramBotMessageService>();
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        private void InternalHandle(Message message)
        {
            TelegramBotMessageManager.Message.Value = message;
            var userService = servicesContainer.GetService <ITelegramBotUserService>();
            var currentUser = userService.GetCurrentUserInfo();

            if (currentUser == null)
            {
                currentUser = userService.RegisterUser();
            }

            TelegramBotLanguageHelper.InitializeCulture(currentUser.Language);

            var context = new MessageContext();

            context.Message     = message;
            context.UserService = userService;
            context.User        = currentUser;
            context.UserRole    = userService.GetCurrentUserRole();

            var handlers = GetMessageHandlers();

            for (int index = 0; index < handlers.Count; index++)
            {
                var handler = handlers[index];
                if (index < handlers.Count - 1)
                {
                    context.NextHandler = handlers[index + 1];
                }

                handler.Initialize(servicesContainer);
                handler.Handle(context);
                if (!context.IsCanExecuteNextHandler)
                {
                    break;
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="servicesProvider"></param>
 public virtual void Initialize(ITelegramBotServicesProvider servicesProvider)
 {
     ServicesProvider          = servicesProvider;
     TelegramBotCommandFactory = servicesProvider.GetService <ITelegramBotCommandFactory>();
 }
示例#7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="servicesProvider"></param>
 public override void Initialize(ITelegramBotServicesProvider servicesProvider)
 {
     base.Initialize(servicesProvider);
     CallbackQueryService = servicesProvider.GetService <ITelegramBotCallbackQueryService>();
 }