public async Task PersistTokenDetail(LivechatUserToken livechatUserToken)
        {
            if (string.IsNullOrEmpty(livechatUserToken.Stores))
            {
                return;
            }

            // Formatting
            var stores = string.Join(",",
                                     livechatUserToken.Stores
                                     .Split(',')
                                     .Select(t => $"|{t}|"));

            livechatUserToken.Stores = stores;

            var dbToken = context.LivechatUserToken
                          .Where(t => t.AuthToken == livechatUserToken.AuthToken &&
                                 t.Device == livechatUserToken.Device &&
                                 t.PushToken == livechatUserToken.PushToken &&
                                 t.Stores == stores)
                          .FirstOrDefault();

            if (dbToken != null)
            {
                return;
            }

            await context.LivechatUserToken.AddAsync(livechatUserToken);

            await context.SaveChangesAsync();
        }
示例#2
0
        /// <summary>
        /// It adds a simple payload in json format joint with customer
        /// </summary>
        /// <param name="livechatUserId">User livechatId</param>
        /// <param name="payload">Dictionary format payload</param>
        /// <returns>Async method</returns>
        public async Task AddPayloadToUser(
            string livechatUserId,
            string channelId,
            Dictionary <string, object> payload,
            bool overwritePayload = true)
        {
            var dbPayload = await context
                            .LivechatChannelUser
                            .FirstOrDefaultAsync(t =>
                                                 t.LivechatUserId == livechatUserId &&
                                                 t.LivechatChannelId == channelId
                                                 );

            if (dbPayload == null)
            {
                return;
            }

            if (!overwritePayload && !string.IsNullOrEmpty(dbPayload.Payload))
            {
                return;
            }

            dbPayload.Payload = JsonConvert.SerializeObject(payload);

            context.LivechatChannelUser.Update(dbPayload);

            await context.SaveChangesAsync();
        }
        /// <summary>
        /// Write a log on database
        /// </summary>
        /// <param name="logLevel">Defines how critical it is</param>
        /// <param name="shortMessage">Brief of the message</param>
        /// <param name="fullMessage">Full body message</param>
        /// <returns></returns>
        public async Task RecLog(
            NopLogLevel logLevel,
            string shortMessage,
            string fullMessage = "")
        {
            var logMessage = new LogModel
            {
                LogLevelId   = logLevel,
                ShortMessage = shortMessage,
                FullMessage  = fullMessage
            };

            await context.Log.AddAsync(logMessage);

            await context.SaveChangesAsync();
        }
        public async Task EndChat(string channelId)
        {
            var channel = await context.LivechatChannel
                          .Where(t => t.Id == channelId)
                          .FirstOrDefaultAsync();

            if (channel == null)
            {
                return;
            }

            channel.IsFinished = true;

            context.LivechatChannel.Update(channel);
            await context.SaveChangesAsync();
        }
示例#5
0
        public async Task CreateLog(LivechatMessagePack pack)
        {
            await context.LivechatMessagePack.AddAsync(pack);

            await context.SaveChangesAsync();
        }