The Context Service is part of the Live Assist for Microsoft Dynamics 365 SDK (Live Assist SDK). The Context Service allows bots to build contextual information about their engagements with visitors, so that it can be made available to Agent within the CRM when they grab a chat. The Bot must collect the Context Data before sending it onto the Context Service. The Context Data collects asserted visitor details and information about the visitor's interaction on your website.

Step 1 — Extend the C# Bot as an Example Quick Start

This article follows on from the Bot created in the first article on our series:

This article will extend the code example found in the first article to:

Make Echo Bot build some context data for a visitor,

Encrypt the data and pass it to the Live Assist Context Service

Enable the Live Assist Context Serviceto collect the context data.

Step 2 — Code Changes to Echobot as an Enabler

There is an extra dependency added to the project.json file:

"jose-jwt": "2.4.0"

The code changes for Function Bots are identical to the code changes in Step 2 of the Web App Bot Context Service. Rather than unnecessarily duplicate the descriptions of the node the extended code snippets for this example are in our Git Repository

Step 3 — Generate and managing a public/private key pair for the Context Service

Just like in our Web App Bot article, this bot will need have access to a Certificate Key Store, loaded into Azure.

This is the recommended approach for loading certificate stores in code, as it does not rely on the developer having access to the private key. The certificate store can be retrieved from the Azure bot framework using a fingerprint. The process is outlined in the Microsoft Azure App Service Documentation . Function bots require the same configuration for managing Certificate Stores.

Each bot must create it's own public/private key pair so that it can encrypt the Context Data sent to the Live Assist Context Service. Your Live Assist organization must be provided the public-key to decypt the data.

You can then see the private certificate and corresponding thumbprint, specified in code:

This should be the same as the fingerprint produced in Step 3 and specified in the Jwt.csx code.

There are numerous ways to generate private keys, so the following is only provided as an example. Please be familiar with the common certificate and certificate-store file extensions such as (pem, crt, cer and .pfx). This example uses a self-signed certificate pair generated with OpenSSL. Developing bots may require different RSA keys or provide certificates signed by your organization's CA.