예제 #1
0
        public async Task <IActionResult> AddUpdateVKUser([FromBody] TokenModel token)
        {
            var vk          = new VkClient();
            var tokenString = await vk.GetToken(token);

            var vkuser = await vk.GetUserByCode(tokenString);

            var user = new UserDTO();

            if (vkuser != null)
            {
                user = new UserDTO
                {
                    Id        = vkuser.Id,
                    FirstName = vkuser.FirstName,
                    LastName  = vkuser.LastName,
                    Domain    = vkuser.Domain,
                };
            }

            try
            {
                UserAction.AddUpdateUser(user);
                var tknbck = new TokenBack()
                {
                    Token = tokenString,
                    Id    = user.Id
                };
                return(Ok(tknbck));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
예제 #2
0
        public IActionResult AddUpdateVKUser([FromBody] AuthVKModel model)
        {
            var user = new UserDTO
            {
                Id     = model.Id,
                Domain = model.Domain,
            };

            if (UserAction.AddUpdateUser(user))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("Ошибка при добавлении пользоватиеля"));
            }
        }
예제 #3
0
        static async void OnMessage(object sender, MessageEventArgs e)
        {
            try
            {
                switch (e.Message.Text)
                {
                case "/start":
                    var isUserRegistred = (bool)UserAction.UserAddedTelegram(e.Message.Chat.Id);
                    if (!isUserRegistred)
                    {
                        await botClient.SendTextMessageAsync(
                            chatId : e.Message.Chat.Id,
                            text : "Нажмите Подтвердить, чтобы получать уведомления. ВНИМАНИЕ: подтверждая, вы передаете БЮРО свой номер телефона для регистрации в системе.",
                            replyMarkup : new ReplyKeyboardMarkup(KeyboardButton.WithRequestContact("Подтвердить")));
                    }
                    else
                    {
                        await botClient.SendTextMessageAsync(
                            chatId : e.Message.Chat.Id,
                            text : "Вы уже подписаны"
                            );
                    }

                    break;

                //case "Test":
                //    Dictionary<long, List<PostDTO>> posts = new Dictionary<long, List<PostDTO>>();
                //    posts.Add(127354174, new List<PostDTO> {
                //    new PostDTO() {
                //        FirstName = "Ольга",
                //        LastName = "Бузова",
                //        AvatarUrl = "https://sun9-60.userapi.com/c850324/v850324431/1dffa8/EfHhV4TGJHc.jpg?ava=1",
                //        Text = "Такой потрясающий день🙏🏻 Просто самая лучшая перезарядка🤤🥰 В кругу близких, детишек, на свежем воздухе....природа, устрицы, гребешки 🤤🤤🤤 провожали закат 🌅 Наслаждаюсь каждой секундой 🥰 я люблю тебя жизнь ❤",
                //        Tags = new string[2]{ "#отдых", "#тревл" },
                //        Likes = 8861,
                //        PostUrl = "https://vk.com/olgabuzova?z=photo32707600_457250122%2Falbum32707600_00%2Frev",
                //        Images = new string[1]{ "https://sun9-71.userapi.com/c543105/v543105535/50cb6/Nxirt3LCSes.jpg" }
                //    },
                //    //new PostDTO() {
                //    //    Text = "222 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                //    //},
                //    //new PostDTO() {
                //    //    Text = "333 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                //    //    Images = new string[3]{"https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Telegram_2019_Logo.svg/1200px-Telegram_2019_Logo.svg.png",
                //    //    "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Telegram_2019_Logo.svg/1200px-Telegram_2019_Logo.svg.png",
                //    //    "https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Telegram_2019_Logo.svg/1200px-Telegram_2019_Logo.svg.png"}
                //    //}
                //     });
                //    SendMessages(posts);
                //    break;
                default:
                    if (e.Message.Contact != null && e.Message.Contact != null)
                    {
                        string replyText = "Благодарим за подписку";
                        var    userDto   = UserAction.GetUserByPhone(e.Message.Contact.PhoneNumber);
                        if (userDto.ChatId != e.Message.Chat.Id)
                        {
                            if (userDto == null)
                            {
                                userDto = new BLL.DTO.UserDTO()
                                {
                                    FirstName = e.Message.Contact.FirstName,
                                    LastName  = e.Message.Contact.LastName,
                                    Phone     = e.Message.Contact.PhoneNumber,
                                    ChatId    = e.Message.Chat.Id
                                };
                            }
                            else
                            {
                                userDto.ChatId = e.Message.Chat.Id;
                            }
                            UserAction.AddUpdateUser(userDto);
                        }
                        else
                        {
                            replyText = "Вы уже подписаны";
                        }
                        await botClient.SendTextMessageAsync(
                            chatId : e.Message.Chat.Id,
                            text : replyText,
                            replyMarkup : new ReplyKeyboardRemove()
                            );
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }