Exemple #1
0
        public static async Task ReplaceFreshDeskBotStateAsync(BotConversationState botConversationState, ILogger log)
        {
            try
            {
                //Connect to DB
                await EnsureCosmosDBAsync(log);

                ItemResponse <BotConversationState> botConversationStateResponse = await botStateContainer.ReadItemAsync <BotConversationState>(botConversationState.FreshDeskId, new PartitionKey(botConversationState.FreshDeskId));

                var itemBody = botConversationStateResponse.Resource;

                // update bot watermark
                itemBody.BotWatermark = botConversationState.BotWatermark;

                // replace the item with the updated content
                botConversationStateResponse = await botStateContainer.ReplaceItemAsync <BotConversationState>(itemBody, botConversationState.FreshDeskId, new PartitionKey(botConversationState.FreshDeskId));

                log.LogInformation("Updated watermark to {0} for FreshDesk ID {1} with conversation ID {2}\n", itemBody.BotWatermark, itemBody.FreshDeskId, itemBody.BotConversationId);
            }
            catch (Exception ex)
            {
                log.LogError("Exception occurred in ReplaceFreshDeskBotStateAsync: {1}", ex);
                throw;
            }
        }
Exemple #2
0
        public static async Task AddItemsToContainerAsync(BotConversationState botConversationState, ILogger log)
        {
            try
            {
                //Connect to DB
                await EnsureCosmosDBAsync(log);

                // Read the item to see if it exists.
                ItemResponse <BotConversationState> botConversationStateResponse = await botStateContainer.ReadItemAsync <BotConversationState>(botConversationState.FreshDeskId, new PartitionKey(botConversationState.FreshDeskId));

                log.LogInformation("Conversation in database corresponding to FreshDeskId: {0} already exists\n", botConversationStateResponse.Resource.BotConversationId);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                try
                {
                    // Create an item in the container
                    ItemResponse <BotConversationState> botConversationStateResponse = await botStateContainer.CreateItemAsync(botConversationState, new PartitionKey(botConversationState.FreshDeskId));

                    log.LogInformation("Created item in database with ConversationId: {0} \n", botConversationStateResponse.Resource.BotConversationId);
                }
                catch (Exception ex2)
                {
                    log.LogError("Exception occurred in AddItemsToContainerAsync: {1}", ex2);
                    throw;
                }
            }
        }