protected override async Task <CommandResult> InternalExecute(StartDtc tdDto)
        {
            var bot   = _telegramFactory.GetTelegramBot();
            var usage = @"به دکتر سلام خوش امدید";
            await bot.SendTextMessageAsync(tdDto.Message.Chat.Id, usage,
                                           replyMarkup : new ReplyKeyboardHide());

            var keyboard = new ReplyKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    new KeyboardButton("\U0001F4A1 درباره ما")
                },
                new[]     // last row
                {
                    new KeyboardButton("شناخت طبع مواد خوراکی"),
                    new KeyboardButton("درمان بیماری ها با طب سنتی"),
                    //new KeyboardButton("\U0001F4F7 کد عکس"),
                }
            }, resizeKeyboard: true);
            await bot.SendTextMessageAsync(tdDto.Message.Chat.Id, "انتخاب کنید",
                                           replyMarkup : keyboard);

            return(new CommandResult());
        }
Beispiel #2
0
        protected override async Task <CommandResult> InternalExecute(IllnessDtc dtc)
        {
            var bot = _telegramFactory.GetTelegramBot();
            await
            bot.SendTextMessageAsync(dtc.Message.Chat.Id, "مشکل مورد نظرتان را وارد کنید",
                                     replyMarkup : BackToMenu());

            return(new CommandResult());
        }
Beispiel #3
0
 public TelegramListener(ILifetimeScope scope, ITelegramClientService telegramFactory)
 {
     _scope           = scope;
     _telegramFactory = telegramFactory;
     _cache           = _telegramFactory.GetCache();
     _bot             = _telegramFactory.GetTelegramBot();
     _allowUser       = new List <string> {
         "Ars4m", "eliakbari"
     };
 }
        protected override async Task <CommandResult> InternalExecute(AboutUsDtc dtc)
        {
            var bot = _telegramFactory.GetTelegramBot();
            await
            bot.SendTextMessageAsync(dtc.Message.Chat.Id,
                                     "این بات برای بالا بردن اطلاعات عمومی در مورد طب سنتی است و به مرور کامل خواهد شد خوشحال می شوم در این راه به من کمک کنید. @ars4m",
                                     replyMarkup : BackToMenu());

            //await bot.SendTextMessageAsync(dtc.Message.Chat.Id, "آدرس ما",
            //    replyMarkup:  BackToMenu());
            //await bot.SendLocationAsync(dtc.Message.Chat.Id, 35.808138370388164f, 51.395888328552246f);
            //await bot.SendPhotoAsync(dtc.Message.Chat.Id, "AgADAgADtqcxG0MlCUiuLUO0e4doxQ0zSw0ABKfCIQPk-UuOlc4DAAEC");
            return(new CommandResult());
        }
Beispiel #5
0
        public async Task <CommandResult> Execute(TDto dto)
        {
            var commandResult = new CommandResult();
            var bot           = _telegramFactory.GetTelegramBot();
            var cache         = _telegramFactory.GetCache();
            await bot.SendChatActionAsync(dto.Message.Chat.Id, ChatAction.Typing);

            if (dto is SaveCommandBaseDto)
            {
                var userMessageData = (UserMessageDataDto)cache.Get(dto.Message.Chat.Id.ToString());
                if (userMessageData == null)
                {
                    userMessageData = new UserMessageDataDto
                    {
                        ChatId      = dto.Message.Chat.Id,
                        LastCommand = typeof(TDto).Name,
                        UserName    = dto.Message.Chat.Username
                    };
                    var policy = new CacheItemPolicy {
                        SlidingExpiration = TimeSpan.FromMinutes(5)
                    };
                    cache.Add(dto.Message.Chat.Id.ToString(), userMessageData, policy);
                }
                else
                {
                    userMessageData.LastCommand = typeof(TDto).Name;
                    var policy = new CacheItemPolicy {
                        SlidingExpiration = TimeSpan.FromMinutes(5)
                    };
                    cache.Add(dto.Message.Chat.Id.ToString(), userMessageData, policy);
                }
                var user = await _telegramUserRepo.QueryAsync(async f => await f.FirstOrDefaultAsync(x => x.UserId == dto.Message.Chat.Id));

                user.LastCommand = typeof(TDto).Name;
                await _telegramUserRepo.SaveAsync(user);
            }
            try
            {
                commandResult = await InternalExecute(dto);
            }
            catch (Exception exp) {
                _logger.Error(new FaultDto("TelegramCommandBase", exp.GetMessage(), exp.StackTrace, FaultSource.Endpoint));
                commandResult.AddError(exp.GetMessage());
            }
            return(commandResult);
        }
        protected override async Task <CommandResult> InternalExecute(CheckUserDtc tdDto)
        {
            var user = await _telegramUserRepository.QueryAsync(async f => await f.FirstOrDefaultAsync(x => x.UserId == tdDto.Message.Chat.Id));

            if (user != null)
            {
                var cache = _telegramFactory.GetCache();

                var userMessageData = new UserMessageDataDto
                {
                    ChatId      = tdDto.Message.Chat.Id,
                    LastCommand = user.LastCommand,
                    UserName    = tdDto.Message.Chat.Username
                };
                var policy = new CacheItemPolicy {
                    SlidingExpiration = TimeSpan.FromMinutes(5)
                };
                cache.Add(tdDto.Message.Chat.Id.ToString(), userMessageData, policy);
            }
            else
            {
                var bot   = _telegramFactory.GetTelegramBot();
                var usage = @"به دکتر سلام خوش امدید";
                await bot.SendTextMessageAsync(tdDto.Message.Chat.Id, usage,
                                               replyMarkup : new ReplyKeyboardHide());

                var keyboard = new ReplyKeyboardMarkup(new[]
                {
                    new[] // first row
                    {
                        new KeyboardButton("\U0001F4A1 درباره ما")
                    },
                    new[] // last row
                    {
                        new KeyboardButton("شناخت طبع مواد خوراکی"),
                        new KeyboardButton("درمان بیماری ها با طب سنتی"),
                        //new KeyboardButton("\U0001F4F7 کد عکس"),
                    }
                }, resizeKeyboard: true);
                await bot.SendTextMessageAsync(tdDto.Message.Chat.Id, "انتخاب کنید",
                                               replyMarkup : keyboard);
            }

            return(new CommandResult());
        }
        protected override async Task <CommandResult> InternalExecute(BackToMenuDtc dtc)
        {
            var cache = _telegramFactory.GetCache();
            var bot   = _telegramFactory.GetTelegramBot();

            cache.Remove(dtc.Message.Chat.Id.ToString());
            var keyboard = new ReplyKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    new KeyboardButton("\U0001F4A1 درباره ما")
                },
                new[]     // last row
                {
                    new KeyboardButton("شناخت طبع مواد خوراکی"),
                    new KeyboardButton("درمان بیماری ها با طب سنتی"),
                    //new KeyboardButton("\U0001F4F7 کد عکس"),
                }
            }, resizeKeyboard: true);
            await bot.SendTextMessageAsync(dtc.Message.Chat.Id, "انتخاب کنید",
                                           replyMarkup : keyboard);

            return(new CommandResult());
        }
Beispiel #8
0
        protected override async Task <QueryResult> InternalExecute(GetIllnessDtq dtq)
        {
            var name  = dtq.Message.Text.SafeFarsiStr();
            var count = await _illnessRepository.CountAsync(x => x.Name == name);

            var bot = _telegramClientService.GetTelegramBot();

            if (count == 1)
            {
                var illness =
                    await
                    _illnessRepository.QueryAsync(
                        async f => await f.FirstOrDefaultAsync(x => x.Name == name));

                await
                bot.SendChatActionAsync(dtq.Message.Chat.Id, ChatAction.Typing);
                await SendMessage(illness.Treatment.Trim(), dtq.Message.Chat.Id, bot);
            }
            else if (count > 1)
            {
                var illnesses =
                    await
                    _illnessRepository.QueryAsync(
                        async f => await f.Where(x => x.Name == name).ToListAsync());

                foreach (var illness in illnesses)
                {
                    await SendMessage(illness.Treatment.Trim(), dtq.Message.Chat.Id, bot);
                }
            }
            else
            {
                var illnesses =
                    await
                    _illnessRepository.QueryAsync(
                        async f => await f.Where(x => x.Name.Contains(name)).OrderBy(x => x.Name).ToListAsync());

                if (illnesses?.Count > 0)
                {
                    var buttons = new KeyboardButton[illnesses.Count][];
                    for (var i = 0; i < illnesses.Count; i++)
                    {
                        buttons[i] = new[] { new KeyboardButton(illnesses[i].Name) };
                    }
                    var keyboard = new ReplyKeyboardMarkup(buttons, true);
                    await
                    bot.SendTextMessageAsync(dtq.Message.Chat.Id, "انتخاب کنید",
                                             replyMarkup : keyboard);
                }
                else
                {
                    _logger.Info(dtq.Message.Text);
                    await
                    bot.SendTextMessageAsync(dtq.Message.Chat.Id, "بیماری یا مشکلی  یافت نشد \n" +
                                             "با نوشتن بخشی از کلمه (بیش از دو حرف) هم می توانید مشکل مورد نظر را جستجو کنید " +
                                             "مثلا برای یافتن حساسيت فصلی می توانید عبارت (حسا) یا (فصل) را وارد کنید",
                                             replyMarkup : BackToMenu());
                }
            }
            return(new QueryResult());
        }
        protected override async Task <QueryResult> InternalExecute(GetMezajTypeDtq dtq)
        {
            var name = dtq.Message.Text.SafeFarsiStr();
            var flag = await _nutritionRepository.QueryAsync(async f => await f.AnyAsync(x => x.Name == name));

            var count = await _nutritionRepository.CountAsync(x => x.Name == name);

            var bot = _telegramClientService.GetTelegramBot();

            if (count == 1)
            {
                #region Old
                //var nutrition =
                //    await
                //        _nutritionRepository.QueryAsync(
                //            async f => await f.Include("MezajType").FirstOrDefaultAsync(x => x.Name == name));
                //await
                //    bot.SendChatActionAsync(dtq.Message.Chat.Id, ChatAction.Typing);
                //await
                //    bot.SendTextMessageAsync(dtq.Message.Chat.Id, $"نام خوراکی : {nutrition.Name.Trim()}\n" +
                //                                                  $"مزاج : {nutrition.MezajType.Name.Trim()}\n" +
                //                                                  $"توضیحات : {nutrition.Description?.Trim()}\n" +
                //                                                  $"@HiDoctor_bot",
                //        replyMarkup: BackToMenu());
                #endregion
                var nutrition =
                    await
                    _nutritionRepository.QueryAsync(
                        async f => await f.Include("MezajType").FirstOrDefaultAsync(x => x.Name == name));

                await
                bot.SendChatActionAsync(dtq.Message.Chat.Id, ChatAction.Typing);
                await SendMessage($"نام خوراکی : {nutrition.Name.Trim()}\n" +
                                  $"مزاج : {nutrition.MezajType.Name.Trim()}\n" +
                                  $"توضیحات : {nutrition.Description?.Trim()}\n", dtq.Message.Chat.Id, bot);
            }
            else if (count > 1)
            {
                var nutritions =
                    await
                    _nutritionRepository.QueryAsync(
                        async f => await f.Include("MezajType").Where(x => x.Name == name).ToListAsync());

                foreach (var nutrition in nutritions)
                {
                    await SendMessage($"نام خوراکی : {nutrition.Name.Trim()}\n" +
                                      $"مزاج : {nutrition.MezajType.Name.Trim()}\n" +
                                      $"توضیحات : {nutrition.Description?.Trim()}\n", dtq.Message.Chat.Id, bot);
                }
            }
            else
            {
                var nutritions =
                    await
                    _nutritionRepository.QueryAsync(
                        async f => await f.Include("MezajType").Where(x => x.Name.Contains(name))
                        .OrderBy(x => x.Name).ToListAsync());

                if (nutritions?.Count > 0)
                {
                    var buttons = new KeyboardButton[nutritions.Count][];
                    // var buttons = nutritions.Select(nutrition => new KeyboardButton(nutrition.Name)).ToArray();
                    for (var i = 0; i < nutritions.Count; i++)
                    {
                        buttons[i] = new[] { new KeyboardButton(nutritions[i].Name) };
                    }
                    var keyboard = new ReplyKeyboardMarkup(buttons, true);
                    await
                    bot.SendTextMessageAsync(dtq.Message.Chat.Id, "انتخاب کنید",
                                             replyMarkup : keyboard);
                }
                else
                {
                    _logger.Info(dtq.Message.Text);
                    await
                    bot.SendTextMessageAsync(dtq.Message.Chat.Id, "خوراکی مورد نظر یافت نشد \n" +
                                             "با نوشتن بخشی از کلمه (بیش از دو حرف) هم می توانید خوارکی مورد نظر را جستجو کنید " +
                                             "مثلا برای یافتن کاکوتی می توانید عبارت (کا) یا (کو) را وارد کنید",
                                             replyMarkup : BackToMenu());
                }
            }
            return(new QueryResult());
        }