/// <summary> /// Handle member added activity in teams. /// </summary> /// <param name="membersAdded">member details.</param> /// <param name="turnContext">turn context.</param> /// <param name="cancellationToken">cancellation token.</param> /// <returns>task.</returns> protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) { try { var activity = turnContext.Activity; this.telemetryClient.TrackTrace($"conversationType: {activity.Conversation.ConversationType}, membersAdded: {activity.MembersAdded?.Count}, membersRemoved: {activity.MembersRemoved?.Count()}"); if (activity.Conversation.ConversationType.Equals("channel")) { if (membersAdded.Any(m => m.Id == activity.Recipient.Id)) { // Bot was added to a team this.telemetryClient.TrackTrace($"Bot added to team {activity.Conversation.Id}"); KbConfiguration kbConfiguration = await this.configurationStorageProvider.GetKbConfigAsync(); if (kbConfiguration == null) { this.telemetryClient.TrackTrace($"Kb has not been created"); await turnContext.SendActivityAsync(MessageFactory.Text(Strings.ErrorMsgText)); } else { await turnContext.SendActivityAsync(MessageFactory.Attachment(this.cards.WelcomeCard())); } } } } catch (Exception ex) { this.telemetryClient.TrackException(ex); } }
/// <summary> /// create knowledge base Id configuration in storage. /// </summary> /// <param name="entity">KbConfiguration entity.</param> /// <returns>Knowledge base configuration details.</returns> public async Task <KbConfiguration> CreateKbConfigAsync(KbConfiguration entity) { if (entity == null) { throw new ArgumentNullException("entity"); } await this.EnsureInitializedAsync(); TableOperation insertOrMergeOperation = TableOperation.InsertOrReplace(entity); TableResult result = await this.configurationCloudTable.ExecuteAsync(insertOrMergeOperation); return(result.Result as KbConfiguration); }
public async Task Run([TimerTrigger("0 */15 * * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log) { try { KbConfiguration kbConfiguration = await this.configurationStorageProvider.GetKbConfigAsync(); if (kbConfiguration == null) { log.LogInformation("Creating knowledge base"); string kbId = await this.qnaServiceProvider.CreateKnowledgeBaseAsync(); log.LogInformation("Publishing knowledge base"); await this.qnaServiceProvider.PublishKnowledgebaseAsync(kbId); KbConfiguration kbConfigurationEntity = new KbConfiguration() { KbId = kbId, }; log.LogInformation("Storing knowledgebase Id in storage " + kbId); try { await retryPolicy.ExecuteAsync(async() => { kbConfiguration = await this.configurationStorageProvider.CreateKbConfigAsync(kbConfigurationEntity); }); } catch (Exception ex) { log.LogError("Error: " + ex.ToString()); log.LogWarning("Failed to store knowledgebase Id in storage. Deleting " + kbId); await this.qnaServiceProvider.DeleteKnowledgebaseAsync(kbId); return; } log.LogInformation("Setup Azure Search Data"); await this.searchServiceDataProvider.SetupAzureSearchDataAsync(kbId); log.LogInformation("Update Azure Search service"); await this.searchService.InitializeSearchServiceDependency(); } else { bool toBePublished = await this.qnaServiceProvider.GetPublishStatusAsync(kbConfiguration.KbId); log.LogInformation("To be Published - " + toBePublished); log.LogInformation("KbId - " + kbConfiguration.KbId); if (toBePublished) { log.LogInformation("Publishing knowledgebase"); await this.qnaServiceProvider.PublishKnowledgebaseAsync(kbConfiguration.KbId); log.LogInformation("Setup Azure Search Data"); await this.searchServiceDataProvider.SetupAzureSearchDataAsync(kbConfiguration.KbId); log.LogInformation("Update Azure Search service"); await this.searchService.InitializeSearchServiceDependency(); } } } catch (Exception ex) { log.LogError("Error: " + ex.Message); // Exception logging. log.LogError(ex.ToString()); } }