Process Multiple Chatdown Files in a Visual Studio Code Task

by Michael Szul on

In my last post we talked about the new Bot Framework Emulator and the Bot Framework's new Chatdown syntax and CLI for prototyping conversations in advance. The syntax allows you to quickly mark up conversations, and then the CLI allows you to transform that syntax into transcripts that the Bot Emulator can then read and display, as if it were an actual chat that just occurred.

Towards the tail end of that post, you saw my PowerShell command for processing multiple files:

Get-ChildItem **/*.chat | ForEach-Object { chatdown "$(Split-Path $_.FullName)/$($_.Name )" >  "$(Split-Path $_.FullName)/$($_.BaseName).transcript" }
      

This command is great--and it's a one-liner--but that's an awful lot to type in. Of course, your alternative is to copy/paste, but what if you wanted to use it in conjunction with your editor or IDE?

I like to use Visual Studio Code, and VSCode has great task execution functionality, so you might be tempted to set this up as a task:

{
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "chatdown",
                  "type": "shell",
                  "command": "Get-ChildItem **/*.chat | ForEach-Object { chatdown \"$(Split-Path $_.FullName)/$($_.Name )\" >  \"$(Split-Path $_.FullName)/$($_.BaseName).transcript\" }",
                  "problemMatcher": []
              }
          ]
      }
      

This was my first instinct too… but it doesn't work. In fact, you'll be denied access to the filesystem to write the transcript files--although the PowerShell command will work if you past it directly into the integrated PowerShell terminal.

After some back-and-forth with the Visual Studio Code team, we discovered that execution does work if you externalize the PowerShell code into a *.ps1 file, and put that into the "command" property of the task.

{
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "chatdown",
                  "type": "shell",
                  "command": "./cd.ps1",
                  "problemMatcher": []
              }
          ]
      }
      

With this, you can now use Visual Studio Code to process all of your chatdown files at once with minimal keystrokes.

For those that don't want to create an external PowerShell file, I'm sure the Visual Studio Code team will have a fix out in no time.