Empower your existing Power Virtual Agents with Bot Framework Skills 🤖
Tags: botframework, powerplatform, azure
Published: 2020-01-31 05:33:29

Are you addressing your day to day customer service operations using Power Virtual Agents? Do you have multiple bots for your organization to cater specific use-cases? Do you want to combine all of them into one experience without re-writing it from the scratch? Would you like to learn how can you maximize your customers outreach by combining the Power Virtual Agent (No-Code) with Bot Framework (Code) bots? If this is what you're looking for then the good news is, Conversational AI team at Microsoft has released support for Skills with Power Virtual Agents and in this post, I will show you how we can add those Skills to our existing Power Virtual Agent.
<blockquote>You may encounter <a href="https://powerusers.microsoft.com/t5/Power-Virtual-Agents-Forum/Can-t-connect-my-PVA-to-the-Skill/td-p/448570">some hurdles</a> while developing it but I am sure my post will definitely help you on the Power Virtual Agent's end as I did a bit of <a href="https://github.com/microsoft/botframework-solutions/issues/2933">struggle</a> <a href="https://github.com/microsoft/botframework-solutions/issues/2897">behind the scenes</a> to get my hands on this.</blockquote>
<h2><img class="aligncenter size-full wp-image-30817" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/compressed-AccountBalance-PVA.gif" alt="Account Balance with Bot Framework Skills" width="1364" height="652" /></h2>
<h2>Skills</h2>
Skills are the bot (read: extensions of a bot) built on Bot Framework SDK v4.7+ that can be used by another bots. For example you've got a HR Bot in your organization which can be extended with the Finance Bot.

Alright! How to get started with that? I think a lot of conversations have been going around but... I would suggest you to go <a href="https://docs.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0&amp;tabs=cs">HERE.</a> However, after following this <a href="https://docs.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0&amp;tabs=cs">tutorial</a>, I am sure you're going to get stuck at something which I really want to highlight in my post.

As this is not a Skills 101 post, you must be a <em><strong>bot developer</strong></em> to understand the basics of it. Secondly, I will only discuss my learning on manifest and Azure AD as these were the only tricky parts of the whole development to connect with Power Virtual Agent. Also note that the current docs are absolutely good for Bot (v4.7) to Bot (v4.7) communication with no strings attached. ❤

<blockquote>If you're in Sydney and want to learn more about Power Virtual Agents hidden gems, Bot Framework Composer and much more then don't forget to join my session at the <a href="https://powerplatform-saturday-sydney2020.eventbrite.com/">Power Platform Bootcamp!</a></blockquote>

<h3>First, appsettings.json 👈</h3>
In this file, you just have to add like this:
<pre class="EnlighterJSRAW" data-enlighter-language="json">{
  "MicrosoftAppId": "&lt;your app Id&gt;",
  "MicrosoftAppPassword": "&lt;your app password&gt;",
  "AllowedCallers": [
    "&lt;your PVA ID&gt;"
  ]
}</pre>
Your PVA ID for allow list can be found here:

<img class="aligncenter size-full wp-image-30811" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/Skills.png" alt="PVA ID" width="506" height="216" />
<h2>The Azure AD Challenge 🏂</h2>
It is super important to note that to add a skill to PVA, the user signed in PVA can only add a skill that is in her/his tenant. Also, there's an <a href="https://github.com/microsoft/botframework-solutions/pull/2587/files">issue</a> which is being tracked by the Product team i.e. if you're developing a bot using Skill's template so it won't populate the home page of App Registration with the bot's URL.

I created the Skill with the basic Echo Bot template therefore, I did an easy trick; changed the Home Page URL manually by going to the App Registration in Azure AD (or from Bot Channels Registration).

<img class="aligncenter size-full wp-image-30815" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/AzureAD-HomePage.png" alt="" width="980" height="422" />
<h2>The Manifest Challenge 🏋️‍♀️</h2>
When I started exploring about Skills, I found out 4-6 types of different <a href="https://github.com/microsoft/botframework-solutions/blob/master/skills/csharp/calendarskill/manifestTemplate.json">manifests</a> but all of them were proved to be old (<em>manifest 1.0</em>) or wrong, not because they were badly written but the Conversational AI Teams (Bot Framework SDK, Virtual Assistant and PVA) are improving their products and services and it's one of the starting phases of unification. Anyway, I landed to the <a href="https://powerusers.microsoft.com/t5/Power-Virtual-Agents-Forum/Can-t-connect-my-PVA-to-the-Skill/td-p/448570">official forum</a> for Power Virtual Agents where I interacted with the product team (thanks to Pawan, Salem &amp; Mr. Chuck) and they worked with me closely to sort this out.

Now, if you check out this <a href="https://docs.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0&amp;tabs=cs#skill-manifest">manifest file</a>, it's perfect for Bot to Bot communication but when I tried to add it in my PVA, it said 0 input, 0 output. It means you can't pass anything to your skill hence it won't respond back.

<img class="aligncenter size-full wp-image-30812" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/0input0output.png" alt="0 Input 0 output" width="550" height="257" />

So to fix this, if you just add this snippet to your manifest.json then it will give you 1 input 0 output. 1 input because I'm going to ask for an <strong><em>accountNumber </em></strong>from PVA.
<pre class="EnlighterJSRAW" data-enlighter-language="json">"activities": {
   "message": {
     "type": "message",
     "description": "Receives the user's' utterance and attempts to resolve it using the skill's LU models",
     "value": {
       "$ref": "#/definitions/accountNumber"
     }
   }
 },
 "definitions": {
   "accountNumber": {
     "type": "object",
     "required": [
     ],
     "properties": {
       "locale": {
         "type": "string",
         "description": "The current user's locale ISO code"
       }
     }
   }</pre>
Your full manifest will then look like this:
<pre class="EnlighterJSRAW" data-enlighter-language="json">{
  "$schema": "https://schemas.botframework.com/schemas/skills/skill-manifest-2.0.0.json",
  "$id": "AMABankSkill",
  "name": "AMA Bank Skill bot",
  "version": "1.0",
  "description": "This skill extends the banking operations to facilitate the customer",
  "publisherName": "Arafat Tehsin",
  "privacyUrl": "https://www.arafattehsin.com/blog",
  "copyright": "Copyright (c) Arafat Tehsin. All rights reserved.",
  "license": "",
  "iconUrl": "https://www.arafattehsin.com/wp-content/uploads/2018/09/logo.png",
  "tags": [
    "arafat tehsin",
    "amabank",
    "bank"
  ],
  "endpoints": [
    {
      "name": "default",
      "protocol": "BotFrameworkV3",
      "description": "Default endpoint for the skill",
      "endpointUrl": "&lt;your endpoint for the Skill&gt;",
      "msAppId": "&lt;your Azure Bot Channel Registration app Id for the Skill&gt;"
    }
  ],
  "activities": {
    "message": {
      "type": "message",
      "description": "Receives the user's' utterance and attempts to resolve it using the skill's LU models",
      "value": {
        "$ref": "#/definitions/accountNumber"
      }
    }
  },
  "definitions": {
    "accountNumber": {
      "type": "object",
      "required": [
      ],
      "properties": {
        "locale": {
          "type": "string",
          "description": "The current user's locale ISO code"
        }
      }
    }
  }</pre>
Bingo! Now if you try to add your Skill to your PVA, you will see something like this:

<img class="aligncenter size-full wp-image-30816" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/1input0output.png" alt="1 Input 0 Output" width="878" height="379" />

This means, you're good to go with your Skill now. It can be added as an action. It will receive a message, send the activity from the Skill (even if the activity contains rich content like Adaptive Cards) and keep going back and forth, until Skill sends <a href="https://docs.microsoft.com/en-us/azure/bot-service/skill-implement-skill?view=azure-bot-service-4.0&amp;tabs=cs#to-continue-or-complete-a-conversation">endOfConversation</a> activity.

<img class="aligncenter size-full wp-image-30821" src="https://www.arafattehsin.com/wp-content/uploads/2020/01/checkbalance.png" alt="Check Balance Topic for Power Virtual Agent" width="1060" height="773" />

I hope now it's good enough for you to give it a shot. If you want more help around it, please contact me on <a href="https://www.twitter.com/arafattehsin">Twitter</a>, <a href="https://www.linkedin.com/in/arafattehsin">LinkedIn</a> or anywhere you like and I'll be happy to assist you.

Until next time.