This article introduces the Live Assist for Microsoft Dynamics 365 Bot Agent Connector API, running as a Node JS Bot within the Azure Functions Bot Framework.
The examples contained here do not provide a detailed guide for developing bots within the Microsoft Azure framework. We assume that the developer has experience with Javascript, Node JS, and the Microsoft Azure Framework and that they are able to use this quick start guide as a starting point to become familiar with the Live Assist Bot Agent Connector API.
Note: The Microsoft Functions Bot Framework is currently in development. You may need to make some changes in the steps, or the code, for your development effort.
The Javascript code shown here is almost identical to that shown in the Web App Bot article.
This bot acts as an Agent, using the Azure Direct Channel connection, and requires appropriate configuration and license allocation in the Live Assist Administration Portal.
Step 1—Creating a Node JS Basic Function Bot
- In Azure, create a new Basic Node JS Function Bot.
- Set the appropriate Storage and Billing requirements for your application (F0 is adequate for development).
The significant parts of this process are:- Selecting a name which is unique within Azure
- Selecting the Node JS (Basic) Application
This process may take Azure a few minutes to build.
Step 2—Downloading the Bot in Azure Functions
- When the Function Bot has been created, you can build and download the Azure Functions'project as a zip file to develop it locally.
Step 3—Build the Project Locally for Azure Deployment using Funpack
- Open the source code locally with your preferred IDE.
- Install
funcpack
:npm install -g azure-functions-pack
.
(using Node JS package manager https://www.npmjs.com/get-npm ) - Install the dependency (botbuilder) by running
npm install
insidemessages
folder. - Edit the code of the Bot under
messages\index.js
which just contains your Bot logic:
"use strict"; var builder = require("botbuilder"); var botbuilder_azure = require("botbuilder-azure"); var path = require('path'); var useEmulator = (process.env.NODE_ENV == 'development'); var connector = useEmulator ? new builder.ChatConnector() : new botbuilder_azure.BotServiceConnector({ appId: process.env['MicrosoftAppId'], appPassword: process.env['MicrosoftAppPassword'], openIdMetadata: process.env['BotOpenIdMetadata'] }); /*---------------------------------------------------------------------------------------- * Bot Storage: This is a great spot to register the private state storage for your bot. * We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! * For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure * ---------------------------------------------------------------------------------------- */ var tableName = 'botdata'; var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']); var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient); var bot = new builder.UniversalBot(connector); bot.localePath(path.join(__dirname, './locale')); bot.set('storage', tableStorage); const TRANSFER_MESSAGE = 'transfer to '; bot.dialog('/', function (session) { session.send('XXX' + session.message.text); switch(session.message.sourceEvent.type) { case "visitorContextData": //process context data if required. This is the first message received so say hello. session.send('Hi, I am an echo bot and will repeat everything you said.'); break; case "systemMessage": //react to system messages if required break; case "transferFailed": //react to transfer failures if required break; case "otherAgentMessage": //react to messages from a supervisor if required break; case "visitorMessage": // Check for transfer message if(session.message.text.startsWith(TRANSFER_MESSAGE)){ var transferTo = session.message.text.substr(TRANSFER_MESSAGE.length); var msg = new builder.Message(session).sourceEvent({directline: {type: "transfer", agent: transferTo}}); session.send(msg); }else { session.send('You said ' + session.message.text); } break; default: session.send('This is not a Live Assist message ' + session.message.sourceEvent.type); } }); if (useEmulator) { var restify = require('restify'); var server = restify.createServer(); server.listen(3978, function() { console.log('test bot endpont at http://localhost:3978/api/messages'); }); server.post('/api/messages', connector.listen()); } else { module.exports = connector.listen(); }
- Package the code by running
funcpack pack ./
inbot-src
:PS ..\NodeJSFuncBot-src\bot-src> funcpack pack ./ info: Generating project files/metadata info: Webpacking project info: Complete!
Step 4—Upload the .funpack/index.js to f messages in Azure Functions Editor
Step 5—Save and Run your bot
- When the code is ready, you can Save and Run the bot. Compilation Errors are shown in the Error/Warning Log at the bottom of the screen. Also, Function Bots record invocation logs under the Monitor window. From here can get the status of any messages sent to the bot:
Step 6—Creating a Direct Line Channel Connector
See: Creating a Direct Line Channel Connector
Step 7—Configuring an Engagement
If you are developing bots on a production organization, be aware that the bot may answer any chats that are started, unless the bot user is allocated to a Skill Group within the Engagement Portal, then set up an engagement that routes to this skill.
- In the Engagement Portal, Go to the left panel and select User and Skills, then select the Skills tab and add skills
- create a new Skill called BotSkill:
- Allocate the skill to the Bot User:
- Assign the BotSkill to the Engagement:
- In the same way, create a Skill Group MySkill and assign it to one of your human agents, to test the transfer.
Step 8—Testing the Bot
The bot is now ready to test using Live Assist for Microsoft Dynamics 365 engagement.
Note: You can use the Trial Engagement for testing if required.
- Visitor Side:
- When the User types: 'tranfer to MySkill' the chat is routed through to the MySkill Group and the assigned Agent can answer it:
Debugging Web App Bots
There are numerous ways to debug your bot application. The following Microsoft documents may assist you with this:
- Diagnosing runtime issues with the Failed Request Traces option.
See: https://docs.microsoft.com/en-us/azure/app-service/web-sites-enable-diagnostic-log - The Kudu Console also provides access to the file system where logs are written.
Pre-Chat Survey
If your engagement has a pre-chat survey, the information collected is available to an agent in the Chat Activity, after the bot has transferred the chat.
Post-chat Survey
Information collected on a post-chat survey is added to the Chat Activity. It will show after the Chat activity has been completed.
The transcript clearly labels the bot, agent and visitor, as well as other Information.