Blog Post

Modern Work App Consult Blog
2 MIN READ

Tips of Building Custom Action in Bot Framework Composer V2

freistli's avatar
freistli
Icon for Microsoft rankMicrosoft
May 06, 2022

Custom Action is the important method to extend Bot App functionalities through C# in Bot Framework Composer for the low code bot solution. Using it, we can create complicated actions for our bots, including re-constructing turn activity results, image converting, math algorithms, adaptive responses to different channels, etc. This official article provides good sample steps to build a simple Customer Action:

 

Create custom actions in Bot Framework Composer | Microsoft Docs

 

However there are still several key parts should be paid attention to. The Custom Action cannot work as expected if we ignore them.  Here are details:

 

  1. The name of the .schema file must match the Kind variable defined in the <MyCustomActionDialog>.cs file exactly.

 

And it is Case Sensitive.

 

This has been pointed out in the article. Usually developers will not miss this point.

 

  1. Don’t forget to modify the appsettings.json in the bot composer project. Otherwise, after adding the Custom Action in Canvas, and run this bot app, you will see this error:

dialog error: Type <MyCustomActionDialog> not registered in factory.

 

In the appsettings.json file of the bot project (located at YourBotApp\settings)to include the MyCustomActionDialog in the runtimeSettings/components array.

 

   "runtimeSettings": {

 

    …….

   

    "components": [

      {

        "name": "MyCustomActionDialog"

      }

    ],

 

This is easily to be ignored because it is a sub step in the official document.

 

  1. In Bot Framework Composer V2.1.2, when merge the custom schema with powershell update-schema.ps1, need to modify update-schema.ps1, change its statement from:

 

bf dialog:merge "*.schema" "!**/sdk-backup.schema" "*.uischema" "!**/sdk-backup.uischema" "!**/sdk.override.uischema" "!**/generated" "../*.csproj" "../package.json" -o $SCHEMA_FILE

 

To:

 

bf dialog:merge "*.schema" "!**/sdk-backup.schema" "*.uischema" "!**/sdk-backup.uischema" "!**/sdk.override.uischema" "!../generated" "!../dialogs/imported" "../*.csproj" "../package.json" -o $SCHEMA_FILE

 

Otherwise, you will see similar errors during merging schema:

 

 .\update-schema.ps1
Running schema merge.
Finding component files
Error conflicting definitions of CancelDialog.dialog

 

For more details of this issue, refer to:

 

Custom actions merge schema failed error · Issue #8501 · microsoft/BotFramework-Composer (github.com)

 

  1. After running the update-schema.ps1, remember to remove MyCustomActionDialog.schema and the Imported folder from the ..\schemas Folder. Otherwise will see some errors like:

 

Deactivated action. Components of $kind "Microsoft.AdaptiveDialog" are not supported

 

For details of the problem, refer to this github issue:

 

Error when implimenting a custom action: Components of $kind "Microsoft.AdaptiveDialog" are not supported. · Issue #8540 · microsoft/BotFramework-Composer (github.com)

 

With above tips, you should be able to successfully build Custom Action for latest Bot Framework Composer Project.

 

Happy Bot Development!

Updated May 06, 2022
Version 3.0
  • Duncan-Hicksons's avatar
    Duncan-Hicksons
    Copper Contributor

    Thanks freistli. This works well, much appreciated.

     

    Do you know if there's a way to access bot settings in the custom action project?

     

    This post suggests that we just need 

    var botSettings = dc.Parent.State.GetValue("settings");

     

    However if I try that in Visual Studio 2022 I get CS0411 "Type arguments cannot be inferred from usage". Wondering if this is something you've come across.