Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Feature upgrade to support multi-turn QnA response (#34)
Browse files Browse the repository at this point in the history
- Application is modified to handle QnA multi-turn experience. The app will now be able to read mutli-turn QnA pairs added in knowledge base and sends follow up questions for queries. 
- The changes includes bot and configuration app services to handle previous questions and minor code clean up across solution.
  • Loading branch information
abbodh authored Jul 17, 2020
1 parent ee5af10 commit 6f99a66
Show file tree
Hide file tree
Showing 27 changed files with 441 additions and 158 deletions.
88 changes: 64 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,97 @@ products:
description: FAQ Plus bot is a friendly Q&A bot that brings a human in the loop when it is unable to help with an answer from the knowledge base.
urlFragment: microsoft-teams-apps-faqplusv2
---
# FAQ Plus [Version 2] App Template
# FAQ Plus App Template

| [Documentation](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Home) | [Deployment guide](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Deployment-Guide) | [Architecture](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Solution-Overview) |
| ---- | ---- | ---- |

Chatbots are an easy way to provide answers to frequently asked questions by users. However, most chatbots fail to engage with users in a meaningful way because there is no human in the loop when the chatbot fails.
Chatbots on Microsoft Teams are an easy way to provide answers to frequently asked questions by users. However, most chatbots fail to engage with users in a meaningful way because there is no human in the loop when the chatbot fails to answer a question well.

FAQ Plus bot is a friendly Q&A bot that brings a human in the loop when it is unable to help. One can ask the bot a question and the bot responds with an answer if it's in the knowledge base. If not, the bot allows the user to submit a query which then gets posted in a pre-configured team of experts who are help to provide support by acting upon the notifications from within their Team itself.
FAQ Plus bot is a friendly Q&A bot that brings a human in the loop when it is unable to help. A user can ask the bot a question and the bot responds with an answer if it's in the knowledge base. If not, the bot offers the user an option to "Ask an expert", which posts the question to a pre-configured team of experts to provide support. An expert can assign the question to themself, chat with the user to gain more context and add the question to the knowledge base from using a messaging extention so that the next user to ask that same question will get an answer from the chatbot!

**FAQ Plus has following features:**
**The July 2020 (version 3) release of FAQ Plus includes a multi-turn feature to the end user experience. With the multi-turn feature, users will be presented with follow-up options along with an answer to their question. This enables the FAQ Plus bot to answer the user's question with more relevance. Multi-turn follow-up options are programmed directly into the QnA Maker when the tenant admin uploads the Q&A pairs into the knowledge base.**

An end-user interacting with FAQ Plus:
**FAQ Plus provides features to the expert team such as:**
* Adding/editing/deleting/previewing QnA
* Viewing update history of QnA
* View all the existing QnA
* View the original version of the edited QnA
* View details of manually added QnA

![FAQ Plus in action (user view)](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/FAQPlusEndUser.gif)
**Here are some screenshots showing FAQ Plus in action:**

Experts team using FAQ Plus:
* A user interacting with FAQ Plus through chat:

![FAQ Plus in action (experts view)](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/FAQPlusExperts.gif)
![FAQ Plus in action (user view)](https://github.com/OfficeDev/microsoft-teams-faqplusplus-app/wiki/images/FAQPlusEndUser.gif)


### FAQ Plus [Version 2] adds the following new capabilities
* Expert using FAQ Plus:

Members of the experts team will now be able to
- add a new QnA pair to the knowledge base directly using messaging extension
- edit and delete QnA pairs added through the bot
- track history of experts updating QnA pair
- configure the answer to show up as an adaptive card with additional details like title, subtitle, image, etc. instead of usual text based answer
![FAQ Plus in action (experts view)](https://github.com/OfficeDev/microsoft-teams-faqplusplus-app/wiki/images/FAQPlusExperts.gif)

## Legal Notice
This app template is provided under the [MIT License](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/blob/master/LICENSE) terms. In addition to these terms, by using this app template you agree to the following:

- You are responsible for complying with all applicable privacy and security regulations related to use, collection and handling of any personal data by your app. This includes complying with all internal privacy and security policies of your organization if your app is developed to be sideloaded internally within your organization.
* Expert invoking the task module to add QnA pair:

![Invoking_taskmodule1](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Invoking_taskmodule1.png)


* Expert configuring the bot to respond with a hero card as an answer to a question:

![Invoking_taskmodule2](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Invoking_taskmodule2.png)

![Add question screen 1](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/add-question-richcard1.png)


* Expert previewing the QnA pair before saving:

![Preview_Rich_card](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Preview_Rich_card.png)


* Expert updating the QnA pair:

![Updating_Question-ui1](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Updating_Question-ui1.png)

- Where applicable, you may be responsible for data related incidents or data subject requests for data collected through your app.
![Updating_Question-ui2](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Updating_Question-ui2.png)

- Any trademarks or registered trademarks of Microsoft in the United States and/or other countries and logos included in this repository are the property of Microsoft, and the license for this project does not grant you rights to use any Microsoft names, logos or trademarks outside of this repository. Microsoft’s general trademark guidelines can be found [here](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general.aspx).
![Updating_Question-ui4](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Updating_Question-ui4.png)


* Some of the fields are markdown supported and are indicated with "(Markdown supported)" beside the field label:

![Adding_Markdown-Support-1](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Adding_Markdown-Support1.png)


* This is how the card will look like when the bot responds with the answer to the Experts team:

![Adding_Markdown-Support-3](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/Adding_Markdown-Support3.png)


* This is how the card will look like when the bot responds with the answer to the End-user:

![End-user_Rich_Card](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Images/End-user_Rich_Card.png)


## Legal Notice

- Use of this template does not guarantee acceptance of your app to the Teams app store. To make this app available in the Teams app store, you will have to comply with the [submission and validation process](https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/deploy-and-publish/appsource/publish), and all associated requirements such as including your own privacy statement and terms of use for your app.
Please read the license terms applicable to this template [here](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/blob/master/LICENSE). In addition to these terms, you agree to the following:

- You are responsible for complying with all applicable privacy and security regulations, as well as all internal privacy and security policies of your company. You must also include your own privacy statement and terms of use for your app if you choose to deploy or share it broadly.
- This template includes functionality to provide all with required information, and it is your responsibility to ensure the data is presented accurately.
- Use and handling of any personal data collected by your app is your responsibility. Microsoft will not have any access to data collected through your app, and therefore is not responsible for any data related incidents.
- Any Microsoft trademarks and logos included in this repository are property of Microsoft and should not be reused, redistributed, modified, repurposed, or otherwise altered or used outside of this repository.

## Getting started
## Getting Started

Begin with the [Solution overview](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/Solution-overview) to read about what the app does and how it works.
Begin with the [Solution overview](/wiki/Solution-overview) to read about what the app does and how it works.

When you're ready to try out FAQ Plus [Version 2], or to use it in your own organization, follow the steps in the [Deployment guide](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/wiki/DeployementGuide).
When you're ready to try out FAQ Plus, or to use it in your own organization, follow the steps in the [Deployment guide](/wiki/DeployementGuide).

## Feedback

Thoughts? Questions? Ideas? Share them with us on [Teams UserVoice](https://microsoftteams.uservoice.com/forums/555103-public)!

Please report bugs and other code issues [here](https://github.com/OfficeDev/microsoft-teams-apps-faqplusv2/issues/new)
Please report bugs and other code issues [here](/issues/new).

## Contributing

Expand Down
5 changes: 0 additions & 5 deletions Source/GlobalSuppressions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Microsoft.Teams.Apps.FAQPlusPlus.AzureFunction.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
Expand All @@ -22,7 +30,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// <copyright file="ResponseCardPayload.cs" company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>

namespace Microsoft.Teams.Apps.FAQPlusPlus.Common.Models
{
using System.Collections.Generic;
using Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.Models;

/// <summary>
/// Represents the payload of a response card.
/// </summary>
Expand All @@ -17,5 +21,15 @@ public class ResponseCardPayload : TeamsAdaptiveSubmitActionData
/// Gets or sets the response given by the bot to the user.
/// </summary>
public string KnowledgeBaseAnswer { get; set; }

/// <summary>
/// Gets or sets list of previous questions when a follow up prompt is selected.
/// </summary>
public List<QnADTO> PreviousQuestions { get; set; }

/// <summary>
/// Gets or sets a value indicating whether question is from prompt.
/// </summary>
public bool IsPrompt { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public interface IQnaServiceProvider
/// </summary>
/// <param name="question">Question text.</param>
/// <param name="isTestKnowledgeBase">Prod or test.</param>
/// <param name="previousQnAId">Id of previous question.</param>
/// <param name="previousUserQuery">Previous question information.</param>
/// <returns>QnaSearchResult object as response.</returns>
Task<QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase);
Task<QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase, string previousQnAId = null, string previousUserQuery = null);

/// <summary>
/// This method is used to update Qna pair in Kb.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,30 @@ public async Task DeleteQnaAsync(int questionId)
/// </summary>
/// <param name="question">Question text.</param>
/// <param name="isTestKnowledgeBase">Prod or test.</param>
/// <returns>QnaSearchResult result as response.</returns>
public async Task<QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase)
/// <param name="previousQnAId">Id of previous question.</param>
/// <param name="previousUserQuery">Previous question information.</param>
/// <returns>QnaSearchResultList result as response.</returns>
public async Task<QnASearchResultList> GenerateAnswerAsync(string question, bool isTestKnowledgeBase, string previousQnAId = null, string previousUserQuery = null)
{
var knowledgeBaseId = await this.configurationProvider.GetSavedEntityDetailAsync(ConfigurationEntityTypes.KnowledgeBaseId).ConfigureAwait(false);

QnASearchResultList qnaSearchResult = await this.qnaMakerRuntimeClient.Runtime.GenerateAnswerAsync(knowledgeBaseId, new QueryDTO()
QueryDTO queryDTO = new QueryDTO()
{
IsTest = isTestKnowledgeBase,
Question = question?.Trim(),
ScoreThreshold = Convert.ToDouble(this.options.ScoreThreshold),
}).ConfigureAwait(false);
};

if (previousQnAId != null && previousUserQuery != null)
{
queryDTO.Context = new QueryDTOContext
{
PreviousQnaId = previousQnAId,
PreviousUserQuery = previousUserQuery,
};
}

return qnaSearchResult;
return await this.qnaMakerRuntimeClient.Runtime.GenerateAnswerAsync(knowledgeBaseId, queryDTO).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration
using Microsoft.Teams.Apps.FAQPlusPlus.Common.Providers;

/// <summary>
/// Autofac configuration
/// Autofac configuration.
/// </summary>
public static class AutofacConfig
{
/// <summary>
/// Register Autofac dependencies
/// Register Autofac dependencies.
/// </summary>
/// <returns>Autofac container</returns>
/// <returns>Autofac container.</returns>
public static IContainer RegisterDependencies()
{
var builder = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration
public static class BundleConfig
{
/// <summary>
/// Register the bundles
/// Register the bundles.
/// </summary>
/// <param name="bundles">Collection of bundles</param>
/// <param name="bundles">Collection of bundles.</param>
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration
public static class FilterConfig
{
/// <summary>
/// Register Global Filters
/// Register Global Filters.
/// </summary>
/// <param name="filters">Collection of global filters.</param>
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration
using System.Web.Routing;

/// <summary>
/// Router Config
/// Router Config.
/// </summary>
public static class RouteConfig
{
/// <summary>
/// Register Routes
/// Register Routes.
/// </summary>
/// <param name="routes">Routes collection</param>
/// <param name="routes">Routes collection.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.Teams.Apps.FAQPlusPlus.Configuration
using Microsoft.Owin.Security.OpenIdConnect;

/// <summary>
/// Startup file
/// Startup file.
/// </summary>
public partial class Startup
{
Expand Down
Loading

0 comments on commit 6f99a66

Please sign in to comment.