Пример #1
0
        /// <summary>
        /// Executing command
        /// </summary>
        /// <param name="message">Message from user</param>
        /// <param name="botClient">Bot Client</param>
        /// <param name="context">DB Context</param>
        /// <param name="markups">Keyboards</param>
        /// <returns></returns>
        public override async Task Execute(Message message, TelegramBotClient botClient, ApplicationContext context,
                                           TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var lang = message.From.LanguageCode;

            // Add new user
            var user = context.Users.FirstOrDefault(p => p.TelegramId == chat.Id);

            if (user == null)
            {
                Enum.TryParse(lang, out UserLang userLang);
                user = new User()
                {
                    TelegramId = chat.Id, Name = chat.FirstName, Lang = userLang
                };
                await context.Users.AddAsync(user);

                await context.SaveChangesAsync();
            }

            var line = await context.Lines.FindAsync("hello");

            var helloText = line.GetTranslate(user.Lang);

            await botClient.SendTextMessageAsync(chat.Id, string.Format(helloText, user.Name),
                                                 replyMarkup : markups.GetMainMarkup(user.Lang));
        }
Пример #2
0
        public override async Task Execute(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database

            // If user not registered
            if (user == null)
            {
                return;
            }

            var main = (await context.Lines.FindAsync("main")).GetTranslate(user.Lang);

            await client.SendTextMessageAsync(user.TelegramId, main, replyMarkup : markups.GetMainMarkup(user.Lang));
        }