示例#1
0
 public TelegramController(IBotSubscriptionService botSubscriptionService, IBotService botService,
                           IPlanService planService)
 {
     _botSubscriptionService = botSubscriptionService;
     _botService             = botService;
     _planService            = planService;
 }
示例#2
0
        private static async Task Subscribe(Message message, string planId)
        {
            IServiceScope           scope = _serviceProvider.CreateScope();
            IBotSubscriptionService botSubscriptionService =
                (IBotSubscriptionService)scope.ServiceProvider.GetService(typeof(IBotSubscriptionService));

            try
            {
                PlanServiceModel result = await botSubscriptionService.CreateBotSubscriptionAsync(
                    new BotSubscriptionServiceModel
                {
                    ChatId = message.Chat.Id.ToString(),
                    PlanId = planId
                });

                await _client.SendTextMessageAsync(message.Chat.Id,
                                                   $"You have successfully subscribed to '{result.Name}' plan.");
            }
            catch (DomainServicesException exception)
            {
                await _client.SendTextMessageAsync(message.Chat.Id, exception.Message);
            }
        }
示例#3
0
        private static void Process()
        {
            IServiceScope           scope = _serviceProvider.CreateScope();
            IBotSubscriptionService botSubscriptionService =
                (IBotSubscriptionService)scope.ServiceProvider.GetService(typeof(IBotSubscriptionService));

            foreach (BotSubscriptionServiceModel botSubscription in botSubscriptionService.GetAll())
            {
                var todayTopics = botSubscriptionService.GetActualTopics(botSubscription.PlanId).ToList();

                if (todayTopics.Any())
                {
                    foreach (var topic in todayTopics)
                    {
                        _client.SendTextMessageAsync(botSubscription.ChatId,
                                                     $"Your today's topic is {topic.Name}\r\nDue date: {topic.EndDate}.\r\nSource: {topic.Source}\r\nGood luck!").GetAwaiter().GetResult();
                    }
                }
                else
                {
                    //TODO add plan.IsFinished
                }
            }
        }
 public TelegramNotificationJob(IBotSubscriptionService botSubscriptionService, IBotService botService)
 {
     _botSubscriptionService = botSubscriptionService;
     _botService             = botService;
 }