Example configuration Microsoft Flow to setup an Automated Errors and Solutions bot
Prerequisites
-
A Microsoft QnA Maker set up, filled with a knowledge base (KB):
For example: Errors & Solutions
Introduction
In this guide you will create a Microsoft Flow solution, in which you create a Flow that will answer error messages based on a Knowledge Base.
Create SharePoint list
-
Navigate to the UCC Config page
-
Open Site Content
-
Select Create an App
-
Select Custom List
-
Give the list a name, for example "Errorlog"
-
Add the following columns:
-
EntryType: Single line of Text
-
Source: Single line of Text
-
Message: Multiple line of Text
-
Solution: Multiple line of Text
-
The end result should look like:
Write error messages to SharePoint
Create PowerShell script
-
Log into the Anywhere365 Server
-
Create a folder "C:\Scripts"
-
Create a folder "C:\Scripts\Bin"
-
Copy the following items to the bin folder (located: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\)
-
Microsoft.SharePoint.Client.dll
-
Microsoft.SharePoint.Client.Runtime.dll
-
Microsoft.SharePoint.Client.WorkflowServices.dll
-
-
Create a PowerShell script in "C:\Script" and change the following items:
-
SiteUrl: Site where you created the Error list
-
Username: User with write permissions on the list.
-
SecurePassword: Password of the user.
##############################
# LOGGING #
##############################
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\Scripts\output.txt -append
##############################
# Connect to SharePoint #
##############################
# Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path C:\Scripts\Bin\Microsoft.SharePoint.Client.dll
Add-Type -Path C:\Scripts\Bin\Microsoft.SharePoint.Client.Runtime.dll
Add-Type -Path C:\Scripts\Bin\Microsoft.SharePoint.Client.WorkflowServices.dll
# Specify tenant admin and site URL
$SiteUrl = "https://contoso.sharepoint.com/sites/ucc/ucc"
$ListName = "ErrorLog"
$UserName = "username@domain.com"
$SecurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
# Bind to site collection
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$ClientContext.Credentials = $credentials
$ClientContext.ExecuteQuery()
# Get List
$List = $ClientContext.Web.Lists.GetByTitle($ListName)
$ClientContext.Load($List)
$ClientContext.ExecuteQuery()
##############################
# GET AND CREATE EVENT #
##############################
$event = get-eventlog -LogName "Unified Contact Center" -newest 1
# "Error" - send only error
if ($event.EntryType -eq "Error")
{
$PCName = $env:COMPUTERNAME
$Message = $event | select-object -Expandproperty Message | out-string
$Message = $message.Split([Environment]::NewLine)[6]
$Source = $event | select-object -Expandproperty Source | out-string
$Source = $Source.trim()
$EntryType = $event | select-object -Expandproperty EntryType | out-string
$Message = $message.replace($Source,"").trim()
# Create Single List Item
$ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$NewListItem = $List.AddItem($ListItemCreationInformation)
$NewListItem["Title"] = 'Error Message'
$NewListItem["Message"] = $Message
$NewListItem["Source"] = $Source
$NewListItem["EntryType"] = $EntryType
$NewListItem.Update()
$ClientContext.ExecuteQuery()
}
else
{
write-host "No error found"
write-host "Here is the log entry that was inspected:"
$event
}
-
Create Scheduled Task
-
Open Event Viewer
-
Open Applications and Services Log
-
Right click and select Attach a Task To this Log
-
Give the task a name and select Next
-
Select Next
-
Select Start a program
-
Fill in the following settings:
-
Program / script: powershell.exe
-
Add argument: Location of the PowerShell script, example: C:\Scripts\EmailError.ps1
-
Creating the Flow
-
Trigger
The trigger for this flow is "When an item is created" in SharePoint. This way the flow will run every time an error is submitted.
- Site Address: Url of the UCC Configuration with the Error list
- List name: Errorlog
-
Html to text
This is needed to remove the Html from the error message.
- Content: Message
-
Call the QnA Maker
Add an action “Generate answer”, a QnA bot action type. The information for his step can be found in your KB, under “My Knowledge Bases”, press view code to see the HTTP Request information.
- Knowledge Base Id: the id between ‘POST /knowledgebases/xxxx-xxxx-xxxxx-xxx/generateAnswer
- Service Host: The https address in the second line (without Host in front)
- Endpoint Key: the endpointKey in the third line
- Question: The plain text content
Leave the Top on 1, for it to return the highest possible answer.
-
Initialize variable
As the output of the QnA Maker action is in the form of a JSON, the next step is to translate this to a string.
- Name: Answer
- Type: String
- Value: Expression "first(body('Generate_answer')?['Answers'])?['answer']"
-
Update item
Next step is to put the answer back in SharePoint.
- Site Address: Url of the UCC Configuration with the Error list
- List Name: ErrorLog
- Id: Id
- Title: Title
- Solution: Answer
The end result should look like:
Did you find this page helpful?
Yes No
Sorry about that
Why wasn't this helpful? (check all that apply)
Thank you for your feedback.
Want to tell us more?
Email your feedback to our documentation team.
Great!
Thanks for taking the time to give us some feedback.