public JsonResult SendMessage() { DataManagement dm = new DataManagement(); if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (User)Session["user"]; var contact = Convert.ToInt32(Request.Form["contact"]); string socket_id = Request.Form["socket_id"]; string userMessage = String.Empty; int userId = currentUser.id; if (!Global.GetCommandList().Contains(Request.Form["message"].Split('=')[0])) { userMessage = Request.Form["message"]; } else { //Llamar bot IBot MyBot = BotFactory.GiveResponse(); userMessage = MyBot.ResponseBot(Request.Form["message"].Split('=')[1].ToString()); userId = dm.GetUser("BOT").id; } Conversation convo = new Conversation { sender_id = userId, message = userMessage, receiver_id = contact }; dm.SaveConversation(convo); var conversationChannel = getConvoChannel(currentUser.id, contact); pusher.TriggerAsync( conversationChannel, "new_message", convo, new TriggerOptions() { SocketId = socket_id }); return(Json(convo)); }