/// <summary>
        /// Send a list of channels to agent
        /// </summary>
        /// <param name="agentLivechatUserId">Agent id</param>
        /// <param name="connectionId">Agent's connection Id</param>
        /// <returns>List of channels</returns>
        public virtual async Task <List <LivechatChannel> > SendChannelListToAgent(string connectionId, string agentLivechatUserId)
        {
            var onlineUsers = await userTracker.UsersOnline();

            // Removes current user (agent) from this verification
            onlineUsers = onlineUsers.Where(t => t.LivechatUserId != agentLivechatUserId);

            // Get agent channels
            var channels = await uow
                           .GetRepository <ChannelRepository>()
                           .GetAgentChannels(agentLivechatUserId);

            // Check list of channels and assign HasOnlineUsers when they have online users
            foreach (var channel in channels)
            {
                channel.HasOnlineUsers = onlineUsers.Any(t =>
                                                         t.Channels.Any(c => c.ChannelId == channel.ChannelId)
                                                         );
            }

            // Send channels list
            await clientsManager
            .Client(connectionId)
            .SendAsync(HubMessages.ACTIVE_CHANNELS, channels);

            return(channels);
        }
示例#2
0
        public static async Task <Store> GetStoreAsync(
            UOW uow,
            int storeId)
        {
            var store = StoreCredentials
                        .Where(t => t.Id == storeId)
                        .FirstOrDefault();

            if (store != null)
            {
                return(store);
            }

            var storeRep = uow.GetRepository <StoreRepository>();

            store = await storeRep.GetAICredentials(storeId);

            if (store == null)
            {
                var log = uow.GetRepository <LogRepository>();
                await log.RecLog(Core.Logger.NopLogLevel.Error, $"Loja não encontrada. Utilizado failover para loja 1. LojaId: {storeId}");

                return(await GetStoreAsync(uow, 1));
            }

            StoreCredentials.Add(store);
            return(store);
        }
        public async Task <MessageResponse> SendMessageAsync(string message, string lastContext = "")
        {
            var storeCredentials = await StoreCredentialsCache.GetStoreAsync(uow, storeId);

            if (storeCredentials == null)
            {
                var logRep = uow.GetRepository <LogRepository>();
                await logRep.RecLog(
                    NopLogLevel.Error,
                    LogMessages.Fmt(LogMessages.STORE_CREDENTIALS_NOT_FOUND, storeId)
                    );

                return(null);
            }

            var conversation = new ConversationService(
                storeCredentials.Username,
                storeCredentials.Password,
                ConversationService.CONVERSATION_VERSION_DATE_2017_05_26
                );

            var response = conversation.Message(storeCredentials.WorkspaceId, new MessageRequest
            {
                Input   = new { text = message },
                Context = string.IsNullOrEmpty(lastContext) ? null : JsonConvert.DeserializeObject(lastContext)
            });

            response.Context = JsonConvert.SerializeObject(response.Context);

            return(response);
        }
示例#4
0
        public LivechatController(
            LivechatRules livechatRules,
            UOW uow)
        {
            this.livechatRules = livechatRules;
            this.uow           = uow;

            logRepository = uow.GetRepository <LogRepository>();
        }
示例#5
0
        public async Task <IActionResult> RegisterToken([FromBody] TokenDetail token)
        {
            // Persists on database
            // TODO: Get AuthToken from query/header instead of param
            var user = HttpContext.User;

            var livechatUserToken = uow.GetRepository <LivechatUserTokenRepository>();
            await livechatUserToken.PersistTokenDetail(new LivechatUserToken
            {
                AuthToken      = user.FindFirstValue("AuthToken") ?? "",
                PushToken      = token.Token,
                Device         = token.Device,
                Version        = token.Version,
                LivechatUserId = user.FindFirstValue("LivechatUserId") ?? "",
                Role           = user.FindFirstValue(ClaimTypes.Role) ?? "",
                Stores         = user.FindFirstValue("Stores") ?? ""
            });

            return(Ok());
        }
示例#6
0
        /// <summary>
        /// It updates payload
        /// </summary>
        /// <param name="extraPayload"></param>
        /// <returns></returns>
        public async Task UpdatePayload(Dictionary <string, object> extraPayload)
        {
            var userDetails = await CurrentUserDetails();

            var userStoreId        = userDetails.CustomerStoreId;
            var userCurrentChannel = await livechatRules.GetCustomerChannel(
                userStoreId,
                userDetails.LivechatUserId
                );

            var storeRepository = uow.GetRepository <StoreRepository>();
            var store           = await storeRepository.GetAICredentials(userStoreId);

            var city = await storeRepository.GetCity(store.CityId);

            extraPayload.Add("nome", userDetails.Payload["name"]);
            extraPayload.Add("telefone", userDetails.Payload["phone"]);
            extraPayload.Add("loja", userDetails.Payload["currentStore"]);
            extraPayload.Add("store", store);
            extraPayload.Add("city", city);

            var userRepository = uow.GetRepository <UserRepository>();

            //userDetails.Payload[3] =
            await userRepository.SetNewUserPayloadFromWidget(
                channelId : userCurrentChannel.ChannelId,
                newPayload : extraPayload,
                exceptUserId : userDetails.LivechatUserId);

            await CurrentUser.SendAsync(HubMessages.EDIT_CUSTOMER_PROFILE_SAVED);

            /*
             * await conversationHandler.PersistPayload(
             *  livechatUserId: userDetails.LivechatUserId,
             *  channelId: userCurrentChannel.ChannelId,
             *  userPayload: userDetails.Payload,
             *  overwritePayload: false
             * ); */
            return;
        }
        public async Task <IActionResult> GetStoreStyle(int storeId)
        {
            if (storeId == 0)
            {
                return(BadRequest());
            }

            var storeRepository = uow.GetRepository <StoreRepository>();
            var style           = await storeRepository.GetStoreStyle(storeId);

            if (string.IsNullOrEmpty(style))
            {
                return(Ok(new { style = "" }));
            }

            var styleJson = JsonConvert.DeserializeObject(style);

            return(Ok(new { style }));
        }
        public async Task <IActionResult> SendQuestionForm([FromBody] QuestionFormData questionForm)
        {
            // Get seller emails list
            var storeRepository = uow.GetRepository <StoreRepository>();
            var adminLojaEmails = await storeRepository.GetAdminsEmailFromStore(questionForm.StoreId);

            // Send an email for each person in store
            var emailService = new SendGridEmail("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");

            // Read email template
            var emailTemplate = string.Empty;

            using (var reader = new StreamReader(Path.Combine(environment.ContentRootPath, "EmailTemplates", "client_without_agent.html")))
            {
                emailTemplate = await reader.ReadToEndAsync();
            }

            // Send emails
            var tempEmailTemplate = string.Empty;

            foreach (var email in adminLojaEmails)
            {
                tempEmailTemplate = emailTemplate
                                    .Replace("{{name}}", questionForm.Name)
                                    .Replace("{{contact}}", questionForm.Phone)
                                    .Replace("{{message}}", questionForm.Message);

                await emailService.EnviarEmail(
                    to : email.Email,
                    header : tempEmailTemplate,
                    subject : "Cliente sem atendimento!",
                    fromAddress : "*****@*****.**",
                    name : "Chat Moveleiros",
                    textPlain : $"O cliente {questionForm.Name} não foi atendido. " +
                    $"O contato informado é {questionForm.Phone}. " +
                    $"A mensagem deixada foi {questionForm.Message}"
                    );
            }

            return(Ok());
        }
示例#9
0
        public static async Task <List <LivechatEntityValueAI> > GetEntityValuesAsync(
            UOW uow,
            string entity,
            int storeId)
        {
            var lowerEntity = entity.ToLower();

            var query = Entities
                        .Where(t => t.StoreId == storeId && t.Id == lowerEntity);

            var result = query.FirstOrDefault();

            if (result != null)
            {
                return(result.EntitiyValues);
            }

            var entityRep = uow.GetRepository <EntityRepository>();
            var entityDb  = await entityRep.GetEntityAI(storeId, lowerEntity);

            Entities.Add(entityDb);

            return(entityDb.EntitiyValues);
        }
示例#10
0
 public StatusController(UOW uow)
 {
     logRepository = uow.GetRepository <LogRepository>();
 }