How to debug Bot Framework Skill locally or via Power Virtual Agent
Tags: botframework, skill, powervirtualagent, debug
Published: 2020-03-22 15:38:12

---
title: How to debug Bot Framework Skill locally or via Power Virtual Agent
published: true
description: 
tags: botframework,skill,powervirtualagent,debug
---

Microsoft announced [Bot Framework Skill](https://microsoft.github.io/botframework-solutions/overview/skills/) (still in preview) last year, and now you can also call skills from Power Virtual Agent. It's straight forward to build the skill by following information [here](https://microsoft.github.io/botframework-solutions/skills/tutorials/create-skill/csharp/1-intro/), but I couldn't find how to debug. So I share what I found so far.

# Debug message type action

The message type action is exactly same as normal bot, so I simply use Bot Framework Emulator to debug it. No issues.

# Debug event type action

There are two types of debug I want to try.

- Local debug
- Remote debug

## Local debug

Let's start from local debug first. Currently I cannot create and send event type activity for action via Bot Framework emulator, but when I read about [event here](https://microsoft.github.io/botframework-solutions/virtual-assistant/handbook/events/) and looking at [EventDebuggerMiddleware.cs](https://github.com/microsoft/botframework-solutions/blob/master/sdk/csharp/libraries/microsoft.bot.solutions/Middleware/EventDebuggerMiddleware.cs), I realize I can simply send text message with following format.

```
/event:{name:"<ActionName>",value:"<Input parameter as json>"}
```

I also update IsSkill method in ITurnContextEx.cs to hack the function to return true when it comes via emulator and the activity type is event.

```csharp
public static class ITurnContextEx
{
    public static bool IsSkill(this ITurnContext turnContext)
    {
        if (turnContext.Activity.Type == ActivityTypes.Event && turnContext.Activity.ChannelId == "emulator")
            return true;

        return turnContext.TurnState.Get<ClaimsIdentity>("BotIdentity") is ClaimsIdentity botIdentity && SkillValidation.IsSkillClaim(botIdentity.Claims) ? true : false;
    }
}
```

That's it. The following screens are taken when I debug out of box sample action. I specify "SampleAction" as action name, and input by following input type.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/214116/6154339e-d299-2be4-4726-801a9e93ecea.png)

## Remote debug

I also want to debug the skill when it's called via assistant bot or Power Virtual Agent. As PVA has a bit more steps, I share the step to debug via PVA.

1\. Run ngrok to create public host.

```shell
ngrok http --host-header=localhost:3987 3978
```

2\. Update manifest-1.0.json and enter ngrok https address.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/214116/ad8b23ce-53bc-88fc-a843-be8726a190af.png)

3\. Update "homepage" information of Azure AD application which I registered for the skill bot.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/214116/0c110eb5-eef8-0cb1-eb57-4e5f143136b4.png)

4\. Remove existing skill and re-add the skill to PVA.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/214116/ac4035eb-730c-7365-5583-66718defe52d.png)

5\. Place the breakpoint and test.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/214116/335c073f-2c0b-9d52-0a3f-2640ce1f09de.png)

Happy debugging!