Beispiel #1
0
        public TelegramBotService(ISettingsService settingsService, IPersonalAgentService personalAgentService)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (personalAgentService == null)
            {
                throw new ArgumentNullException(nameof(personalAgentService));
            }

            _personalAgentService = personalAgentService;

            settingsService.CreateSettingsMonitor <TelegramBotServiceSettings>(s => Settings = s);

            Log.WarningLogged += (s, e) =>
            {
                EnqueueMessageForAdministrators($"{Emoji.WarningSign} {e.Message}\r\n{e.Exception}", TelegramMessageFormat.PlainText);
            };

            Log.ErrorLogged += (s, e) =>
            {
                if (e.Message.StartsWith("Sending Telegram message failed"))
                {
                    // Prevent recursive send of sending failures.
                    return;
                }

                EnqueueMessageForAdministrators($"{Emoji.HeavyExclamationMark} {e.Message}\r\n{e.Exception}", TelegramMessageFormat.PlainText);
            };
        }
Beispiel #2
0
        public TelegramBotService(
            ISettingsService settingsService,
            IPersonalAgentService personalAgentService,
            ISystemInformationService systemInformationService,
            ILogService logService,
            IScriptingService scriptingService)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (scriptingService == null)
            {
                throw new ArgumentNullException(nameof(scriptingService));
            }

            _personalAgentService = personalAgentService ?? throw new ArgumentNullException(nameof(personalAgentService));

            _log = logService.CreatePublisher(nameof(TelegramBotService));

            settingsService.CreateSettingsMonitor <TelegramBotServiceSettings>(s => Settings = s.NewSettings);
            systemInformationService.Set("TelegramBotService/IsConnected", () => _isConnected);

            scriptingService.RegisterScriptProxy(s => new TelegramBotScriptProxy(this));
        }
        public TelegramBotService(ISettingsService settingsService, IPersonalAgentService personalAgentService)
        {
            if (settingsService == null) throw new ArgumentNullException(nameof(settingsService));
            if (personalAgentService == null) throw new ArgumentNullException(nameof(personalAgentService));

            _personalAgentService = personalAgentService;

            settingsService.CreateSettingsMonitor<TelegramBotServiceSettings>(s => Settings = s);

            Log.WarningLogged += (s, e) =>
            {
                EnqueueMessageForAdministrators($"{Emoji.WarningSign} {e.Message}\r\n{e.Exception}", TelegramMessageFormat.PlainText);
            };

            Log.ErrorLogged += (s, e) =>
            {
                if (e.Message.StartsWith("Sending Telegram message failed"))
                {
                    // Prevent recursive send of sending failures.
                    return;
                }

                EnqueueMessageForAdministrators($"{Emoji.HeavyExclamationMark} {e.Message}\r\n{e.Exception}", TelegramMessageFormat.PlainText);
            };
        }
Beispiel #4
0
        public TelegramBotService(ISettingsService settingsService, IPersonalAgentService personalAgentService, ILogService logService)
        {
            if (settingsService == null)
            {
                throw new ArgumentNullException(nameof(settingsService));
            }
            if (personalAgentService == null)
            {
                throw new ArgumentNullException(nameof(personalAgentService));
            }

            _personalAgentService = personalAgentService;

            _log = logService.CreatePublisher(nameof(TelegramBotService));

            settingsService.CreateSettingsMonitor <TelegramBotServiceSettings>(s => Settings = s.NewSettings);

            logService.LogEntryPublished += (s, e) =>
            {
                if (e.LogEntry.Severity == LogEntrySeverity.Warning)
                {
                    EnqueueMessageForAdministrators($"{Emoji.WarningSign} {e.LogEntry.Message}\r\n{e.LogEntry.Exception}",
                                                    TelegramMessageFormat.PlainText);
                }
                else if (e.LogEntry.Severity == LogEntrySeverity.Error)
                {
                    if (e.LogEntry.Message.StartsWith("Sending Telegram message failed"))
                    {
                        // Prevent recursive send of sending failures.
                        return;
                    }

                    EnqueueMessageForAdministrators(
                        $"{Emoji.HeavyExclamationMark} {e.LogEntry.Message}\r\n{e.LogEntry.Exception}",
                        TelegramMessageFormat.PlainText);
                }
            };
        }