Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="portalID"></param>
        /// <param name="livechatID"></param>
        /// <returns></returns>
        public bool CloseLiveChatByAgent(int portalID, int livechatID)
        {
            var isClosed = false;

            var objLiveChatInfo = LiveChatManager.Instance.GetLiveChatByID(livechatID);
            if (objLiveChatInfo != null && !objLiveChatInfo.IsClosed)
            {
                LiveChatManager.Instance.CloseLiveChat(livechatID, true);

                var objLiveChatMessageInfo = new LiveChatMessageInfo()
                {
                    LiveChatID = objLiveChatInfo.LiveChatID,
                    CreateDate = DateTime.Now,
                    SentBy = MessageSentBy.System,
                    MessageType = MessageType.Text,
                    Message = "Agent closed the live chat",
                };
                int messageID = LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);
                objLiveChatMessageInfo.MessageID = messageID;

                Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID).closeLiveChatByAgent(objLiveChatInfo.LiveChatID);
                Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID).reciveMessage(objLiveChatMessageInfo);

                //ersal payam be agent ha
                var agents = LiveChatAgentManager.Instance.GetLiveChatAgents(objLiveChatInfo.LiveChatID);
                foreach (var agent in agents)
                {
                    Clients.Group(AgentGroupName + agent.UserID, Context.ConnectionId).reciveMessage(objLiveChatMessageInfo);
                    Clients.Group(AgentGroupName + agent.UserID, Context.ConnectionId).closeLiveChatByAgent(objLiveChatInfo.LiveChatID);
                }

                isClosed = true;
            }
            return isClosed;
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objLiveChatInfo"></param>
        /// <param name="objAgentView"></param>
        /// <param name="sendToVisitor"></param>
        /// <param name="sendToAgent"></param>
        private void AgentHasJoin(LiveChatInfo objLiveChatInfo, AgentView objAgentView, bool sendToVisitor, bool sendToAgent)
        {
            var agent = new LiveChatAgentViewModel()
            {
                AgentID = objAgentView.AgentID,
                UserID = objAgentView.UserID,
                DisplayName = objAgentView.DisplayName,
                Email = objAgentView.Email,
                Avatar = DotNetNuke.Common.Globals.ResolveUrl("~/dnnimagehandler.ashx?mode=profilepic&userid=" + objAgentView.UserID),
                IsOnline = VisitorsOnlineApi.Instance.IsVisitorOnline(objLiveChatInfo.PortalID, objAgentView.UserID),
                JoinDate = DateTime.Now
            };

            LiveChatAgentManager.Instance.AddLiveChatAgent(new LiveChatAgentInfo() { AgentID = agent.AgentID, UserID = agent.UserID, LiveChatID = objLiveChatInfo.LiveChatID, JoinDate = DateTime.Now });

            var objLiveChatMessageInfo = new LiveChatMessageInfo()
            {
                LiveChatID = objLiveChatInfo.LiveChatID,
                SentBy = MessageSentBy.System,
                CreateDate = DateTime.Now,
                MessageType = MessageType.Text,
                Message = objAgentView.DisplayName + " join chat"
            };
            int messageID = LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);
            objLiveChatMessageInfo.MessageID = messageID;

            if (sendToVisitor)
            {
                Clients.Group(objLiveChatInfo.PortalID + "-" + objLiveChatInfo.VisitorGUID).agentHasJoin(objLiveChatInfo.LiveChatID, agent);
                Clients.Group(objLiveChatInfo.PortalID + "-" + objLiveChatInfo.VisitorGUID).reciveMessage(objLiveChatMessageInfo);
            }

            if (sendToAgent)
            {
                foreach (var item in LiveChatAgentManager.Instance.GetLiveChatAgents(objLiveChatInfo.LiveChatID))
                {
                    Clients.Group(AgentGroupName + item.UserID).agentHasJoin(objLiveChatInfo.LiveChatID, agent);
                    Clients.Group(AgentGroupName + item.UserID).reciveMessage(objLiveChatMessageInfo);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="portalID"></param>
        /// <param name="livechatID"></param>
        /// <returns></returns>
        public bool CloseLiveChatByVisitor(int portalID, int livechatID)
        {
            var isClosed = false;

            var objLiveChatInfo = LiveChatManager.Instance.GetLiveChatByID(livechatID);
            if (objLiveChatInfo != null && !objLiveChatInfo.IsClosed)
            {
                LiveChatManager.Instance.CloseLiveChat(livechatID, false);

                var objLiveChatMessageInfo = new LiveChatMessageInfo()
                {
                    LiveChatID = objLiveChatInfo.LiveChatID,
                    CreateDate = DateTime.Now,
                    SentBy = MessageSentBy.System,
                    MessageType = MessageType.Text,
                    Message = "Visitor closed the live chat",
                };
                int messageID = LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);
                objLiveChatMessageInfo.MessageID = messageID;

                Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID).closeLiveChatByVisitor(objLiveChatInfo.LiveChatID);
                Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID).reciveMessage(objLiveChatMessageInfo);

                //ersal payam be agent ha
                var agents = LiveChatAgentManager.Instance.GetLiveChatAgents(objLiveChatInfo.LiveChatID);
                if (!agents.Any(a => a.hasLeft == false)) // agar hich agenti join nashode bayad payam roye tamame agenthaye department ersal shavad
                {
                    var departments = LiveChatDepartmentManager.Instance.GetLiveChatDepartments(objLiveChatInfo.LiveChatID);
                    Clients.Group(DepartmentAgentsGroupName + departments.First().DepartmentID).reciveMessage(objLiveChatMessageInfo);
                    Clients.Group(DepartmentAgentsGroupName + departments.First().DepartmentID).closeLiveChatByVisitor(objLiveChatInfo.LiveChatID);
                }
                else
                {
                    foreach (var agent in agents)
                    {
                        Clients.Group(AgentGroupName + agent.UserID).reciveMessage(objLiveChatMessageInfo);
                        Clients.Group(AgentGroupName + agent.UserID).closeLiveChatByVisitor(objLiveChatInfo.LiveChatID);
                    }
                }

                isClosed = true;
            }
            return isClosed;
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="livechatID"></param>
        public void VisitorHasLeftChat(int livechatID)
        {
            var objLiveChatInfo = LiveChatManager.Instance.GetLiveChatByID(livechatID);
            LiveChatManager.Instance.CloseLiveChat(objLiveChatInfo.LiveChatID, false);

            var objLiveChatMessageInfo = new LiveChatMessageInfo()
            {
                LiveChatID = objLiveChatInfo.LiveChatID,
                CreateDate = DateTime.Now,
                SentBy = MessageSentBy.System,
                MessageType = MessageType.Text,
                Message = "Visitor has left chat",
            };
            int messageID = LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);
            objLiveChatMessageInfo.MessageID = messageID;

            //ersal payam be agent ha
            var agents = LiveChatAgentManager.Instance.GetLiveChatAgents(objLiveChatInfo.LiveChatID);
            if (!agents.Any(a => a.hasLeft == false)) // agar hich agenti join nashode bayad payam roye tamame agenthaye department ersal shavad
            {
                var departments = LiveChatDepartmentManager.Instance.GetLiveChatDepartments(objLiveChatInfo.LiveChatID);
                Clients.Group(DepartmentAgentsGroupName + departments.First().DepartmentID).reciveMessage(objLiveChatMessageInfo);
            }
            else
            {
                foreach (var agent in agents)
                {
                    Clients.Group(AgentGroupName + agent.UserID).reciveMessage(objLiveChatMessageInfo);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="portalID"></param>
        /// <param name="message"></param>
        public void SeenMessage(int portalID, LiveChatMessageInfo message)
        {
            LiveChatMessageManager.Instance.SeenMessage(message.MessageID);

            var objLiveChatInfo = LiveChatManager.Instance.GetLiveChatByID(message.LiveChatID);
            Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID).seenMessage(message.MessageID);
        }
Beispiel #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="portalID"></param>
        /// <param name="message"></param>
        /// <param name="reOpen"></param>
        /// <returns></returns>
        public int SendMessage(int portalID, LiveChatMessageInfo message, bool reOpen = false)
        {
            try
            {
                if (message.SentBy == MessageSentBy.System || message.SentBy == MessageSentBy.Visitor)
                    message.AgentUserID = -1;
                else
                {
                    message.AgentUserID = AgentManager.Instance.GetAgentByUserName(portalID, UserName).UserID;
                }

                message.CreateDate = DateTime.Now;
                message.MessageID = LiveChatMessageManager.Instance.AddMessage(message);

                var objLiveChatInfo = LiveChatManager.Instance.GetLiveChatByID(message.LiveChatID);

                //ersal payam be visitor be joz tab jari
                Clients.Group(portalID + "-" + objLiveChatInfo.VisitorGUID, Context.ConnectionId).reciveMessage(message);

                //ersal payam be agent ha
                var agents = LiveChatAgentManager.Instance.GetLiveChatAgents(objLiveChatInfo.LiveChatID);
                if (!agents.Any(a => a.hasLeft == false)) // agar hich agenti join nashode bayad payam roye tamame agenthaye department ersal shavad
                {
                    var departments = LiveChatDepartmentManager.Instance.GetLiveChatDepartments(objLiveChatInfo.LiveChatID);
                    Clients.Group(DepartmentAgentsGroupName + departments.First().DepartmentID).reciveMessage(message);
                }
                else
                {
                    foreach (var agent in agents)
                    {
                        Clients.Group(AgentGroupName + agent.UserID, Context.ConnectionId).reciveMessage(message);
                    }
                }

                if (objLiveChatInfo.IsClosed)
                {
                    //re open live chat -- next version :)
                }

                return message.MessageID;
            }
            catch
            {
                return -1;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="livechat"></param>
        /// <returns></returns>
        public int StartLiveChatByVisitor(LiveChatViewModel livechat)
        {
            if (LiveChatManager.Instance.hasVisitorOpenedLiveChat(livechat.PortalID, livechat.Visitor.VisitorGUID))
                return 0;

            var visitor = VisitorsOnlineApi.Instance.GetVisitorByGUID(livechat.PortalID, livechat.Visitor.VisitorGUID);

            var objLiveChatInfo = new LiveChatInfo()
            {
                PortalID = livechat.PortalID,
                VisitorGUID = livechat.Visitor.VisitorGUID,
                VisitorName = livechat.Visitor.DisplayName,
                VisitorEmail = livechat.Visitor.Email,
                VisitorUserID = visitor.UserID,
                VisitorIP = visitor.IP,
                VisitorUserAgent = visitor.UserAgent,
                VisitorMessage = livechat.Message,
                CreateDate = DateTime.Now,
                CloseDate = DateTime.MaxValue,
                IsClosed = false,
            };
            int livechatID = LiveChatManager.Instance.AddLiveChat(objLiveChatInfo);
            LiveChatDepartmentManager.Instance.AddLiveChatDepartment(new LiveChatDepartmentInfo()
            {
                LiveChatID = livechatID,
                DepartmentID = livechat.Departments.First().DepartmentID,
                CreateDate = DateTime.Now
            });

            //create messages
            var objLiveChatMessageInfo = new LiveChatMessageInfo()
            {
                LiveChatID = livechatID,
                SentBy = MessageSentBy.System,
                CreateDate = DateTime.Now,
                MessageType = MessageType.Text,
                Message = "Chat started",
            };
            LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);

            if (!string.IsNullOrEmpty(livechat.Message))
            {
                objLiveChatMessageInfo = new LiveChatMessageInfo()
                {
                    LiveChatID = livechatID,
                    SentBy = MessageSentBy.Visitor,
                    CreateDate = DateTime.Now,
                    MessageType = MessageType.Text,
                    Message = livechat.Message
                };
                LiveChatMessageManager.Instance.AddMessage(objLiveChatMessageInfo);
            }

            livechat = GetLiveChatViewModel(objLiveChatInfo);

            //ersale live chat kamel shode be khode visitor(darkhast konande chat)
            Clients.Group(livechat.PortalID + "-" + visitor.VisitorGUID).startLiveChat(livechat);
            //send live chat request to agents
            var department = livechat.Departments.First();
            Clients.Group(DepartmentAgentsGroupName + department.DepartmentID).incomingLiveChat(livechatID, visitor.VisitorGUID, livechat.Message, "add");

            var context = GlobalHost.ConnectionManager.GetHubContext<VisitorsOnlineHub>();
            context.Clients.Group("MyDnnLiveChatAgents-" + department.DepartmentID).invokeScript(string.Format("mydnnLiveChatRequests({0},'add');", livechatID));

            //update visitor info in visitor list 
            visitor.DisplayName = livechat.Visitor.DisplayName;
            visitor.Email = livechat.Visitor.Email;

            //eslah shavad
            ///VisitorsOnlineApi.Instance.UpdateVisitorOnline(livechat.PortalID, visitor.VisitorGUID, visitor.UserName, visitor.DisplayName, visitor.Email, visitor.LastURL, Context.ConnectionId, true);
            //var context = GlobalHost.ConnectionManager.GetHubContext<VisitorsOnlineHub>();
            ///context.Clients.Group("MyDnnVisitorsOnline").updateVisitorInfo(visitor);

            return livechatID;
        }