Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        public static async Task <int> LogCustomerAgentChatAsync(Activity activity)
        {
            try
            {
                // *************************
                // Instantiate the BotData dbContext
                using (var DB = new UserAgentDBEntities())
                {
                    // Create a new CustomerAgentLog object
                    CustomerAgentLog caLog = new CustomerAgentLog();
                    // Set the properties on the CustomerAgentLog object
                    caLog.Channel = activity.ChannelId;
                    caLog.UserID  = activity.From.Id;
                    caLog.created = DateTime.UtcNow;
                    caLog.Message = activity.Text.Truncate(500);
                    // Add the CustomerAgentLog object to CustomerAgentLog
                    DB.CustomerAgentLog.Add(caLog);
                    // Save the changes to the database
                    return(await DB.SaveChangesAsync());
                }
            }
            catch (Exception ex)
            {
                await LogErrorAsync(ex);

                throw;
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="messageRouterResult"></param>
        /// <returns></returns>
        public static async Task <int> CustomerAgentChatHistoryLogAsync(MessageRouterResult messageRouterResult)
        {
            try
            {
                // *************************
                // Instantiate the BotData dbContext
                using (var DB = new UserAgentDBEntities())
                {
                    // Create a new CustomerAgentLog object
                    CustomerAgentLog caLog = new CustomerAgentLog();
                    // Set the properties on the CustomerAgentLog object
                    caLog.Channel = messageRouterResult.Activity.ChannelId;

                    caLog.ChannelId        = messageRouterResult.ConversationClientParty.ChannelAccount.Id;
                    caLog.ChannelName      = messageRouterResult.ConversationClientParty.ChannelAccount.Name;
                    caLog.ConversationId   = messageRouterResult.ConversationOwnerParty.ConversationAccount?.Id;
                    caLog.ConversationName = messageRouterResult.ConversationOwnerParty.ConversationAccount?.Name;

                    caLog.AttendedAgent = messageRouterResult.Activity.From.Name;//messageRouterResult.ConversationOwnerParty.ConversationAccount.Name;
                    caLog.AttendedBy    = messageRouterResult.ConversationOwnerParty.ConversationAccount.Name == null ? 1 : 1;
                    caLog.ServiceURL    = messageRouterResult.ConversationClientParty.ServiceUrl;
                    caLog.DeviceType    = messageRouterResult.Activity.ChannelId;

                    caLog.UserID = System.Web.HttpContext.Current.Session["UserID"] == null ? messageRouterResult.Activity.From.Id : System.Web.HttpContext.Current.Session["UserID"].ToString();

                    caLog.JsonString = messageRouterResult.ConversationClientParty.ToJsonString();

                    caLog.created = DateTime.UtcNow;
                    caLog.Message = messageRouterResult.Activity.Text;
                    // Add the CustomerAgentLog object to CustomerAgentLog
                    DB.CustomerAgentLog.Add(caLog);
                    // Save the changes to the database
                    return(await DB.SaveChangesAsync());
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    await Repository.UtilityRepo.LogMsgAsync(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                                           eve.Entry.Entity.GetType().Name, eve.Entry.State));

                    foreach (var ve in eve.ValidationErrors)
                    {
                        await Repository.UtilityRepo.LogMsgAsync(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                                               ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                await LogErrorAsync(ex);

                throw;
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="conversationParty"></param>
        /// <param name="IsUserAccepted"></param>
        /// <param name="UserName"></param>
        /// <param name="userID"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static async Task <int> CustomerAgentConnectedAsync(Party conversationParty, bool IsUserAccepted, string UserName, string userID, string message)
        {
            try
            {
                // *************************
                // Instantiate the BotData dbContext
                using (var DB = new UserAgentDBEntities())
                {
                    // Create a new CustomerAgentLog object
                    CustomerAgentLog caLog = new CustomerAgentLog();
                    // Set the properties on the CustomerAgentLog object
                    caLog.Channel          = conversationParty.ChannelId;
                    caLog.ChannelId        = conversationParty.ChannelAccount.Id;
                    caLog.ChannelName      = conversationParty.ChannelAccount.Name;
                    caLog.ConversationId   = conversationParty.ConversationAccount?.Id;
                    caLog.ConversationName = conversationParty.ConversationAccount?.Name;

                    caLog.AttendedAgent = UserName;
                    caLog.AttendedBy    = conversationParty.ConversationAccount.Name == null ? 1 : 1;
                    caLog.ServiceURL    = conversationParty.ServiceUrl;
                    caLog.DeviceType    = conversationParty.ChannelId;
                    caLog.UserID        = "Bot";
                    caLog.JsonString    = conversationParty.ToJsonString();

                    caLog.created = DateTime.UtcNow;
                    caLog.Message = message;
                    // Add the CustomerAgentLog object to CustomerAgentLog
                    DB.CustomerAgentLog.Add(caLog);
                    // Save the changes to the database
                    return(await DB.SaveChangesAsync());
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    await Repository.UtilityRepo.LogMsgAsync(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                                           eve.Entry.Entity.GetType().Name, eve.Entry.State));

                    foreach (var ve in eve.ValidationErrors)
                    {
                        await Repository.UtilityRepo.LogMsgAsync(string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                                               ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                await LogErrorAsync(ex);

                throw;
            }
        }