Search through kb articles with Virtual Agent
In this blog I will explain how you can use a Power Virtual Agent and a Power Automate flow to search through Dynamics 365 Customer Service knowledge base articles.
If you are more a video kind of person you can see the solution on my YouTube channel. Otherwise crack on with reading.
Before you can create this flow you will need to install and/or configure three things:
– 30 day trial Power Virtual Agents
– 30 day trial Dynamics 365 Customer Service
– Enable Relevance Search on Environment
Power Virtual Agent
First you start with setting up the virtual agent.
1. Create Power Virtual Agents bot
2. Create a custom topic in your Power Virtual Agents bot
3. Make sure you enter a couple of trigger phrases. In my example I am using phrases like I have an issue and Something is broken.
4. Add a question. Use the Multiple choice options. Define the options for the sure. Also make sure you add a ProductTypeVar so you can save the response into an variable.
5. Add an Call flow action. Create a new Power Automate flow. This will open the Power Automate designer interface.
1. Modify the Power Virtual Agents trigger action. Add a Text Input variable. In this example this is SearchKeyword.
2. Add a Search rows action. Set the row count to 5. Make sure you add a table filter for knowledgearticle table and sort the rows by @search.score desc
3. Add a Initialize variable action. In this action we are going to create a table with Markdown. Paste in line 1 of the code snippet below. Make sure you also add a CR.
4. Add a Append to string variable action. Paste in line 2 of the code snippet of step 3. Make sure you also add a CR.
5. Add a parse json action. Use the list of rows property for the Content. Use the
Microsoft Dataverse Search Rows schema.
6. Add a Select action. Use the title and articlepublicnumber fields from the parse json action. You can obviously use additional properties in this mapping.
7. Add another Append to string variable action. Paste in line 3 of the code snippet of step 3. Make sure you also add a CR. This will place the Append to string variable action within an apply to each loop.
8. Modify the Return value(s) to Power Virtual Agents action. Add a Text output variable. Use the MarkdownTable variable for the content of that text output.
9. Save the flow and return to the authoring canvas of your custom topic.
Input and Output
To finish the configuration of the Virtual Agent we can map the SearchKeyword variable to the ProductTypeVar. And the search results can be presented in a Message action. Use the KBFound variable for that which should contain your markdown table with the 5 most relevant kb articles.
Testing your bot
If you want to test your bot before publishing it you can use the test pane. After finishing the whole setup you should see a test result like in the screenshot below.