Tips of Building Custom Action in Bot Framework Composer V2

Published May 05 2022 07:51 PM 1,030 Views
Microsoft

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 supp...

 

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

 

Happy Bot Development!

%3CLINGO-SUB%20id%3D%22lingo-sub-3329457%22%20slang%3D%22en-US%22%3ETips%20of%20Building%20Custom%20Action%20in%20Bot%20Framework%20Composer%20V2%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3329457%22%20slang%3D%22en-US%22%3E%3CP%3ECustom%20Action%20is%20the%20important%20method%20to%20extend%20Bot%20App%20functionalities%20through%20C%23%20in%20Bot%20Framework%20Composer%20for%20the%20low%20code%20bot%20solution.%20Using%20it%2C%20we%20can%20create%20complicated%20actions%20for%20our%20bots%2C%20including%20re-constructing%20turn%20activity%20results%2C%20image%20converting%2C%20math%20algorithms%2C%20adaptive%20responses%20to%20different%20channels%2C%20etc.%20This%20official%20article%20provides%20good%20sample%20steps%20to%20build%20a%20simple%20Customer%20Action%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcomposer%2Fhow-to-create-custom-actions%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3ECreate%20custom%20actions%20in%20Bot%20Framework%20Composer%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20there%20are%20still%20several%20key%20parts%20should%20be%20paid%20attention%20to.%20The%20Custom%20Action%20cannot%20work%20as%20expected%20if%20we%20ignore%20them.%20%26nbsp%3BHere%20are%20details%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EThe%20name%20of%20the%20.schema%20file%20must%20match%20the%20Kind%20variable%20defined%20in%20the%20%3CMYCUSTOMACTIONDIALOG%3E.cs%20file%20exactly.%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20it%20is%20Case%20Sensitive.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20has%20been%20pointed%20out%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcomposer%2Fhow-to-create-custom-actions%23create-the-schema-file%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Ethe%20article%3C%2FA%3E.%20Usually%20developers%20will%20not%20miss%20this%20point.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDon%E2%80%99t%20forget%20to%20modify%20the%20appsettings.json%20in%20the%20bot%20composer%20project.%20Otherwise%2C%20after%20adding%20the%20Custom%20Action%20in%20Canvas%2C%20and%20run%20this%20bot%20app%2C%20you%20will%20see%20this%20error%3A%3CP%3Edialog%20error%3A%20Type%20%3CMYCUSTOMACTIONDIALOG%3E%20not%20registered%20in%20factory.%3C%2FMYCUSTOMACTIONDIALOG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20appsettings.json%20file%20of%20the%20bot%20project%20(located%20at%20YourBotApp%5Csettings)to%20include%20the%20MyCustomActionDialog%20in%20the%20runtimeSettings%2Fcomponents%20array.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3E%26nbsp%3B%26nbsp%3B%20%22runtimeSettings%22%3A%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%E2%80%A6%E2%80%A6.%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22components%22%3A%20%5B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22name%22%3A%20%22MyCustomActionDialog%22%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%5D%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20easily%20to%20be%20ignored%20because%20it%20is%20a%20sub%20step%20in%20the%20official%20document.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EIn%20Bot%20Framework%20Composer%20V2.1.2%2C%20when%20merge%20the%20custom%20schema%20with%20powershell%20update-schema.ps1%2C%20need%20to%20modify%20update-schema.ps1%2C%20change%20its%20statement%20from%3A%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3Ebf%20dialog%3Amerge%20%22*.schema%22%20%22!**%2Fsdk-backup.schema%22%20%22*.uischema%22%20%22!**%2Fsdk-backup.uischema%22%20%22!**%2Fsdk.override.uischema%22%20%22!**%2Fgenerated%22%20%22..%2F*.csproj%22%20%22..%2Fpackage.json%22%20-o%20%24SCHEMA_FILE%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3Ebf%20dialog%3Amerge%20%22*.schema%22%20%22!**%2Fsdk-backup.schema%22%20%22*.uischema%22%20%22!**%2Fsdk-backup.uischema%22%20%22!**%2Fsdk.override.uischema%22%20%22!..%2Fgenerated%22%20%22!..%2Fdialogs%2Fimported%22%20%22..%2F*.csproj%22%20%22..%2Fpackage.json%22%20-o%20%24SCHEMA_FILE%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOtherwise%2C%20you%20will%20see%20similar%20errors%20during%20merging%20schema%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3E%26nbsp%3B.%5Cupdate-schema.ps1%3CBR%20%2F%3ERunning%20schema%20merge.%3CBR%20%2F%3EFinding%20component%20files%3CBR%20%2F%3EError%20conflicting%20definitions%20of%20CancelDialog.dialog%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20more%20details%20of%20this%20issue%2C%20refer%20to%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotFramework-Composer%2Fissues%2F8501%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3ECustom%20actions%20merge%20schema%20failed%20error%20%C2%B7%20Issue%20%238501%20%C2%B7%20microsoft%2FBotFramework-Composer%20(github.com)%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EAfter%20running%20the%20update-schema.ps1%2C%20remember%20to%20remove%20MyCustomActionDialog.schema%20and%20the%20Imported%20folder%20from%20the%20..%5Cschemas%20Folder.%20Otherwise%20will%20see%20some%20errors%20like%3A%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3EDeactivated%20action.%20Components%20of%20%24kind%20%22Microsoft.AdaptiveDialog%22%20are%20not%20supported%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20details%20of%20the%20problem%2C%20refer%20to%20this%20github%20issue%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotFramework-Composer%2Fissues%2F8540%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EError%20when%20implimenting%20a%20custom%20action%3A%20Components%20of%20%24kind%20%22Microsoft.AdaptiveDialog%22%20are%20not%20supported.%20%C2%B7%20Issue%20%238540%20%C2%B7%20microsoft%2FBotFramework-Composer%20(github.com)%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20above%20tips%2C%20you%20should%20be%20able%20to%20successfully%20build%20Custom%20Action%20for%20latest%20Bot%20Framework%20Composer%20Project.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHappy%20Bot%20Development!%3C%2FP%3E%3C%2FMYCUSTOMACTIONDIALOG%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3329457%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20article%20is%20going%20to%20share%204%20useful%20tips%20of%20building%20Custom%20Action%20in%20Bot%20Framework%20Composer%20V2.1.2.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎May 05 2022 08:08 PM
Updated by: