public TelegramBotService(
            ILogger <TelegramBotService> logger,
            ISensorTempReader sensorTempReader,
            IPhysSensorInfo physSensorInfo,
            IWeatherForecastService weatherForecastService,
            IServiceScopeFactory scopeFactory,
            IOptions <TelegramBotSettings> options)
        {
            this.logger                 = logger;
            this.sensorTempReader       = sensorTempReader;
            this.physSensorInfo         = physSensorInfo;
            this.weatherForecastService = weatherForecastService;
            this.scopeFactory           = scopeFactory;
            telegramBotSettings         = options.Value;
            token = telegramBotSettings.TelegramBotAPIKey;
            LoadTrustedUsersFromDB();
            trustedUsers.CollectionChanged += TrustedUsers_CollectionChanged;

            botClient = new TelegramBotClient(token)
            {
                Timeout = TimeSpan.FromSeconds(10)
            };
            botClient.OnMessage       += BotClient_OnMessage;
            botClient.OnCallbackQuery += BotClient_OnCallbackQuery;
        }
Example #2
0
 public IosAppCommand(IMessagesService messagesService,
                      TelegramBotClient telegramBotClient, TelegramBotSettings settings)
 {
     _messagesService   = messagesService;
     _telegramBotClient = telegramBotClient;
     _settings          = settings;
 }
Example #3
0
        public TelegramBot(ICommChannelHandler commHandler, TelegramBotSettings settings)
        {
            _commandHandler = commHandler as ICommChannelCommandHandler;
            _settings       = settings;

            _mmHandler = commHandler as ICommChannelMultimediaHandler;

            if (_commandHandler is null && _mmHandler is null)
            {
                throw new ArgumentException();
            }

            var httpHandler = new HttpClientHandler
            {
                UseProxy = false
            };
            var httpClient = new HttpClient(httpHandler);

            _client = new TelegramBotClient(_settings.Token, httpClient);

            _client.OnMessage             += Client_OnMessage;
            _client.OnUpdate              += Client_OnUpdate;
            _client.OnReceiveError        += Client_OnReceiveError;
            _client.OnReceiveGeneralError += Client_OnReceiveGeneralError;
        }
Example #4
0
 public FaqCommand(IMessagesService messagesService,
                   TelegramBotClient telegramBotClient, TelegramBotSettings appSettings)
 {
     _messagesService   = messagesService;
     _telegramBotClient = telegramBotClient;
     _appSettings       = appSettings;
 }
Example #5
0
        private static void SetWebhookPath(IApplicationBuilder app, TelegramBotSettings telegramBotSettings)
        {
            var telegramBot = app.ApplicationServices.GetRequiredService <ITelegramBot>();
            var webhookUri  = $"{telegramBotSettings.WebhookUri.Trim('/')}{GetWebhookEndpoint(telegramBotSettings)}";

            telegramBot.SetWebhookAsync(webhookUri, telegramBotSettings.AllowedUpdates);
        }
Example #6
0
 public TelegramChatMessagePublisher(
     TelegramBotSettings botSettings,
     IWebRequestor webRequestor)
 {
     this.botSettings  = botSettings;
     this.webRequestor = webRequestor;
 }
 public TelegramUpdatesReader(
     TelegramBotSettings botSettings,
     IWebRequestor webRequestor)
 {
     this.botSettings  = botSettings;
     this.webRequestor = webRequestor;
 }
        public SmallTalkService(SmallTalkSettings smallTalkSettings, TelegramBotSettings telegramBotSettings)
        {
            var config = new AIConfiguration(smallTalkSettings.Token, SupportedLanguage.Russian);

            ApiAi = new ApiAi(config);

            TelegramBotClient = new TelegramBotClient(telegramBotSettings.Token);
        }
        public BotController(TelegramBotSettings telegramBotConfiguration, IVoiceTranscriberService voiceTranscriberService, ISmallTalkService smallTalkService)
        {
            TelegramBotConfiguration = telegramBotConfiguration;
            VoiceTranscriberService  = voiceTranscriberService;
            SmallTalkService         = smallTalkService;

            TelegramBotClient = new TelegramBotClient(TelegramBotConfiguration.Token);
        }
        public VoiceTranscriberService(
            AzureSpeechToTextSettign azureSpeechToText,
            TelegramBotSettings telegramBotSettings,
            ZamzarSettings zamzarSettings
            )
        {
            AzureSpeechToText = azureSpeechToText;
            ZamzarSettings    = zamzarSettings;

            TelegramBotClient = new TelegramBotClient(telegramBotSettings.Token);
        }
 public ResultModel Update(TelegramBotSettings settings)
 {
     try
     {
         _telegramBotService.UpdateSettings(settings);
         return(ResultModel.Success);
     }
     catch (Exception e)
     {
         _logService.LogError(e);
         return(ResultModel.Error);
     }
 }
Example #12
0
        public static IServiceCollection AddTelegramBotClient
        (
            this IServiceCollection serviceCollection,
            TelegramBotSettings telegramBotConfiguration
        )
        {
            var    client  = new TelegramBotClient(telegramBotConfiguration.Token);
            string webHook = $"{telegramBotConfiguration.Url}/api/message/update";

            client.SetWebhookAsync(webHook).Wait();

            return(serviceCollection
                   .AddTransient <ITelegramBotClient>(x => client));
        }
Example #13
0
        public void UpdateSettings(TelegramBotSettings settings)
        {
            _settingsService.Set("Hooks_TelegramBot_ProxyServer", settings.ProxyServer);
            _settingsService.Set("Hooks_TelegramBot_ProxyPort", settings.ProxyPort);
            _settingsService.Set("Hooks_TelegramBot_ProxyLogin", settings.ProxyLogin);
            _settingsService.Set("Hooks_TelegramBot_ProxyPassword", settings.ProxyPassword);
            _settingsService.Set("Hooks_TelegramBot_AllowedUserPhones", settings.AllowedUserPhones);
            _settingsService.Set("Hooks_TelegramBot_ApiKey", settings.ApiKey);
            _settingsService.Set("Hooks_TelegramBot_WebHookToken", settings.WebHookToken);


            _allowedPhoneNumbers = settings.AllowedUserPhones.Split(',').ToList();
            foreach (var phoneChatId in _phoneChatIds)
            {
                phoneChatId.Allowed = _allowedPhoneNumbers.Any(x => x == phoneChatId.Phone);
            }
        }
Example #14
0
        public void BotSettings()
        {
            // Arrange
            var telegramBotSettings = new TelegramBotSettings();

            telegramBotSettings.Token       = "9878798as987d98";
            telegramBotSettings.TelegramAPI = "https://api.telegram.org/bot";

            var webContentDownloaderMock = new Mock <IWebContentDownloader>();

            webContentDownloaderMock.Setup(s => s.DownloadContent(It.IsAny <string>())).Throws(new Exception("Sorry, telegram is not available!"));

            // Act

            /*var telegramUpdatesReader = new TelegramUpdatesReader(telegramBotSettings, webContentDownloaderMock.Object);
             * var telUpdate = telegramUpdatesReader.GetUpdate();
             *
             * // Assert
             * var error = telUpdate.Should().Contain("404");
             * if (error.Equals("404")) throw (new Exception("Error! 404."));*/
        }
Example #15
0
        public TelegramBotSettings GetSettings()
        {
            string proxyServer      = _settingsService.GetSettings <string>("Hooks_TelegramBot_ProxyServer");
            int    proxyPort        = _settingsService.GetSettings <int>("Hooks_TelegramBot_ProxyPort");
            string proxyLogin       = _settingsService.GetSettings <string>("Hooks_TelegramBot_ProxyLogin");
            string proxyPassword    = _settingsService.GetSettings <string>("Hooks_TelegramBot_ProxyPassword");
            string allowedUserNames = _settingsService.GetSettings <string>("Hooks_TelegramBot_AllowedUserPhones");
            string key   = _settingsService.GetSettings <string>("Hooks_TelegramBot_ApiKey");
            string token = _settingsService.GetSettings <string>("Hooks_TelegramBot_WebHookToken");

            TelegramBotSettings settings = new TelegramBotSettings()
            {
                AllowedUserPhones = allowedUserNames,
                ApiKey            = key,
                ProxyLogin        = proxyLogin,
                ProxyPassword     = proxyPassword,
                ProxyPort         = proxyPort,
                ProxyServer       = proxyServer,
                WebHookToken      = token
            };

            return(settings);
        }
Example #16
0
 private static string GetWebhookEndpoint(TelegramBotSettings telegramBotSettings)
 {
     return($"{WebhookEndpointBase}/{telegramBotSettings.BotAccessToken}");
 }
 public TelegramUpdatesReader(TelegramBotSettings telegramBotSettings, IWebContentDownloader webContentDownloader)
 {
     this.telegramBotSettings  = telegramBotSettings;
     this.webContentDownloader = webContentDownloader;
 }
Example #18
0
 public LykkeApiClient(TelegramBotSettings settings)
 {
     _settings = settings;
 }
Example #19
0
 public static string GetBotApiEndpoint(this TelegramBotSettings botSettings)
 {
     return(string.Format(botSettings.BotApiUrl, botSettings.Token));
 }