Esempio n. 1
0
        public IActionResult CallBack(object json)
        {
            CallbackModel data = JsonConvert.DeserializeObject <CallbackModel>(json.ToString());

            Log.LogInformation($"Callback with data:{data}");
            if (data.Type == "confirmation")
            {
                return(Ok(Config["VkApi:Confirmation"]));
            }

            if (data.Type == "message_new")
            {
                Message message = Message.FromJson(new VkResponse(data.Object));
                Log.LogInformation($"Messasge is:{message}");
                Log.LogInformation($"UserID is :{message.PeerId}");
                User user = Vk.Users.Get(new [] { (long)message.PeerId }).First();
                Log.LogInformation($"User is:{user.LastName} {user.FirstName}");
                var responce = CommandBinding.ProcessMessage(Vk, message);
                Vk.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams()
                {
                    PeerId = message.PeerId, Message = responce, RandomId = new DateTime().Millisecond
                });
            }

            return(Ok("ok"));
        }