internal static DateTime GetLastMessage(string conversationId) { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); return(results.Date != null ? results.Date : DateTime.Now); }
//Get language stored in conversation object using conversation id, if null default to English internal static string GetLanguage(string conversationId) { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); return(results.Language != null && results.Language != "" ? results.Language : "En"); }
//Updates the language stored in the conversation object with user selection //Should eventually be changed to take/ update from database instead internal static async Task UpdateLanguage(string conversationId, string language) { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); results.Language = language; var x = await UserCollection.ReplaceOneAsync(filter, results); }
/* Keep track of the time since the last message the user sent*/ internal async static Task UpdateConvTime(string conversationId) { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); DateTime previousDate = results.Date; results.Date = DateTime.Now; var result = await UserCollection.ReplaceOneAsync(filter, results); }
internal static async Task <bool> SaveConversationAsync(string fromName, string toId, string toName, string serviceUrl, string channelId, string conversationId) { if (channelId != "directline") // updating the time of already existing attribute { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); results.FromName = fromName; results.ToId = toId; results.ToName = toName; results.ChannelId = channelId; var x = await UserCollection.ReplaceOneAsync(filter, results); return(true); } return(false); }
/* Called by root dialog to save new conversation IDs*/ internal static async Task <bool> SaveBasicConversationAsync(string fromId, string serviceUrl, string channelId, string conversationId, bool status) { var exists = UserCollection.AsQueryable().FirstOrDefault(x => x.ConversationId == conversationId) != null; if (!exists) { await UserCollection.InsertOneAsync( new ConversationObject { FromId = fromId, ServiceUrl = serviceUrl, ConversationId = conversationId, Date = DateTime.Now, Status = status, FromName = "", ToId = "", ToName = "", ChannelId = "", Language = "" }); return(true); } else // updating the time of already existing attribute { var filter = Builders <ConversationObject> .Filter.Eq(s => s.ConversationId, conversationId); ConversationObject results = UserCollection.Find(filter).FirstOrDefault(); DateTime previousDate = results.Date; results.Date = DateTime.Now; var result = await UserCollection.ReplaceOneAsync(filter, results); } return(false); }