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

  1. Navigate to the UCCUCC stands for Unified Contact Center and consists of a queue that can be handled by Agents. Each UCC has its own settings, interactive voice response questions and Agents with specific skills. Agents can be member of, or sign up to, one or more UCCs. Config page

  2. Open Site Content

  3. Select Create an App

  4. Select Custom List

  5. Give the list a name, for example "Errorlog"

  6. Add the following columns:

    1. EntryType: Single line of Text

    2. Source: Single line of Text

    3. Message: Multiple line of Text

    4. Solution: Multiple line of Text

The end result should look like:

 

Write error messages to SharePoint

Create PowerShell script

  1. Log into the Anywhere365 Server

  2. Create a folder "C:\Scripts"

  3. Create a folder "C:\Scripts\Bin"

  4. Copy the following items to the bin folder (located: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\)

    1. Microsoft.SharePoint.Client.dll

    2. Microsoft.SharePoint.Client.Runtime.dll

    3. Microsoft.SharePoint.Client.WorkflowServices.dll

  5. 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

  1. Open Event Viewer

  2. Open Applications and Services Log

  3. Right click and select Attach a Task To this Log

  4. Give the task a name and select Next

  5. Select Next

  6. Select Start a program

  7. Fill in the following settings:

    1. Program / script: powershell.exe

    2. Add argument: Location of the PowerShell script, example: C:\Scripts\EmailError.ps1

 

Creating the Flow

  1. 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
  2. Html to text

    This is needed to remove the Html from the error message.

    • Content: Message
  3. 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.

  4. 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']"
  5. 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: