コード例 #1
0
        public void Execute()
        {
            Session session = SessionHelper.GetSession(_messageEventArgs.Message.From.Id);

            if (session.InstructionId.Equals(NextInstruction.None))
            {
                return;
            }

            if (session.InstructionId.Equals(NextInstruction.AddRss))
            {
                if (RssHelper.IsRss(_messageEventArgs.Message.Text.Trim()))
                {
                    Response <RssEntity> Validation = _queryRssService.Get(_messageEventArgs.Message.From.Id, _messageEventArgs.Message.Text.Trim());
                    if (Validation.ResponseData == null)
                    {
                        session.InstructionId = NextInstruction.AddAlias;
                        _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, $"enter alias name for the rss.").GetAwaiter();
                        session.Payload = _messageEventArgs.Message.Text.Trim();
                    }
                    else
                    {
                        _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, "rss is already exist in list.").GetAwaiter();
                    }
                }
                else
                {
                    _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, "rss is not found. please enter valid url.").GetAwaiter();
                }
            }
            else if (session.InstructionId.Equals(NextInstruction.AddAlias))
            {
                Response <int> response = _commandRssService.Add(new RssEntity()
                {
                    Url = session.Payload, AliasName = _messageEventArgs.Message.Text.Trim(), UserId = _messageEventArgs.Message.From.Id
                });
                if (response.Type.Equals(ResponseType.Success))
                {
                    _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, "rss added to list").GetAwaiter();
                    session.InstructionId = NextInstruction.None;
                }
                else if (response.Type.Equals(ResponseType.AlreadyExist))
                {
                    _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, "alias name is already exist. please enter unique name").GetAwaiter();
                }
            }
            else if (session.InstructionId.Equals(NextInstruction.BugReport))
            {
                RssFeedHelper.SaveBugReport($"bug from {_messageEventArgs.Message.Chat.Id}", _messageEventArgs.Message.Text);
                _telegramBotClient.SendTextMessageAsync(_messageEventArgs.Message.Chat.Id, "thank you for your report.").GetAwaiter();
                session.InstructionId = NextInstruction.None;
            }
        }