Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom Action Sample #2950

Merged
merged 14 commits into from
May 13, 2020
Merged

feat: Custom Action Sample #2950

merged 14 commits into from
May 13, 2020

Conversation

luhan2017
Copy link
Contributor

@luhan2017 luhan2017 commented May 8, 2020

Description

In this PR, I added a CustomAction solution in the C# runtime folder which includes the custom code and schema.

Here are the steps to enable CustomAction:

  1. Create a echo bot.
  2. Enable ejected runtime, the runtime will be placed in the bot folder.
  3. In the bot/runtime folder add a project reference in azurewebapp/Microsoft.BotFramework.Composer.WebApp.csproj,
<ProjectReference Include="..\customaction\Microsoft.BotFramework.Composer.CustomAction.csproj" />
  1. Then remove line 28, uncomment line 29 and 139 in azurewebapp/Startup.cs file
using Microsoft.BotFramework.Composer.CustomAction;
// This is for custom action component registration.
ComponentRegistration.Add(new CustomActionComponentRegistration());
  1. Run dotnet build to verifty if it passes build.
EchoBot-9\runtime\azurewebapp>dotnet build
  1. Go to azurewebapp/schemas folder, run update.cmd, the sdk.schema will be updated.
EchoBot-9\runtime\azurewebapp\schemas>update.cmd
  1. Copy the sdk.schema to the bot/schemas
  2. Go back to composer, reopen the bot and you can add a custom action.

Task Item

Create your bot based on custom actions and try out in emulator.

fixes #2824
fixes #2896

Screenshots

image

image

image

image

image

image

@luhan2017 luhan2017 changed the title Custom Action Sample feat: Custom Action Sample May 8, 2020
@a-b-r-o-w-n a-b-r-o-w-n changed the base branch from luhan/rc1 to master May 8, 2020 20:28
@a-b-r-o-w-n a-b-r-o-w-n force-pushed the luhan/customActionSample branch from 48341cf to a41c84d Compare May 8, 2020 20:30
@github-actions
Copy link

github-actions bot commented May 8, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling a41c84d on luhan/customActionSample into fb2b7f0 on master.

@@ -0,0 +1,100 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought since we modified the built-in CSharp template (code + schema), we don't actually need this sample, every sample can be used as customized action sample.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,8901 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an update to the default sdk.schema, instead of creating a new one.

@@ -0,0 +1,25 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary, and doing the schema here and doing the code in another place actually make the CSharp Bot template not "self-contained".

Copy link
Contributor

@boydc2014 boydc2014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

I expect the changes to be

  • Only happened inside BotProject/CSharp/Template
  • add a new MultiplyDialog.schema + MultiplyDialog.cs (self-contained change)
  • update the sdk.schema to include this MultiplyDialog.schema (using dialog:merge)

and that's it, if user run ejection, it would just work, make sense?

@luhan2017
Copy link
Contributor Author

If we want to keep the custom schema "custom", we need keep two versions of schema in composer:

  1. composer/packages/server/schemas/sdk.schema, this is our default schema and should not include custom schema.
  2. runtime/azurewebapp/schemas/sdk.schema. this is default+custom schema.

which means, every time we update the sdk package+schema, we need to keep in mind to do twice of the schema merge for the above two, which doesn't look good for me.

So my hacky way is to put custom schema in the sample folder and when ejection you can customize you sdk.schema by rerun the dialog:merge.

I think both way are not perfect, how about we just explain how to use it in documents. I am not sure providing a single click experience on custom schema is a good direction which will make user confused. ("I don't need to do anything to enable custom schema"?)

@srinaath is working on a readme to explain how to enable this. we can decide whether that is enough for user. if adding this sample just introduces more confusion, let's close this.

@cwhitten @benbrown thoughts?

@hibrenda
Copy link
Contributor

hibrenda commented May 9, 2020

I prefer to let user know how to merge the sdk.schema instead of just give them the customized sdk.schema as if user really use this feature later, he need to know how to do the schema merge.
So until we have the UX trade off to implement this step later, we just provide the readme file(manual step) to user.

For custom schema, there are 2 steps.

  1. custom runtime (self-contained now)
  • The customized runtime can be set up through the ejection
  • User can learn from this sample for how to write a customized code and also how to register the customized code into startup.cs . User can easily extend it based on this sample code.
  1. customized schema (manual for R9)
  • The customized schema (sample) is located in the sample folder
  • User need to follow readme to install bf-dialog tool and manually execute "bf dialog:merge" to get the updated sdk.schema file.
  • Just like we did the manual step for azure provision, if user don't follow the step, they can not make it.

@boydc2014 boydc2014 self-assigned this May 11, 2020
@srinaath
Copy link
Contributor

srinaath commented May 11, 2020

@luhan2017 I used this PR to actually build my README file for adding custom actions. I think there is a lot of value in including this sample and I'm mentioning about this sample in the README too. Granted the PR does a little magic of showing the merged schema directly. But the README coupled with this sample should give a user a good idea to add custom actions.

@hibrenda I will be making a PR today to close #2896 that includes the steps you have mentioned above. We can update that PR if the README is still confusing for someone starting up with Composer

@@ -168,6 +169,9 @@ public void ConfigureServices(IServiceCollection services)
var resourceExplorer = new ResourceExplorer().AddFolder(botDir);
var rootDialog = GetRootDialog(botDir);

// register customized types, please note this is only needed for customized actions.
resourceExplorer.RegisterType<MultiplyDialog>("MultiplyDialog");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luhan2017 so currently the default runtime that is ejected out is going to include this registration for all samples correct? Do you think if we could include this registration only if they eject out CustomActions sample?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we should include it for everyone so they have a clear example of how it works.

@carlosscastro
Copy link
Member

@luhan2017 @benbrown should this be added to the functions runtime as well? If yes, we could place the dialog in the core project (/runtime/core) and then jsut reference it from the web app startup.cs and from the functions startup.cs.

@benbrown
Copy link
Contributor

IMO - yes!

@luhan2017
Copy link
Contributor Author

To who evolved in the PR, @benbrown @benbrown @hibrenda @cwhitten @srinaath

I have removed an action sample and added a custom action project in the runtime folder. which user need to refer to it explicitly to enable it. See the details at the beginning.

@carlosscastro , if user want to enable it for azure function, he/she will need to add a project reference for azure function and add CustomActionComponentRegistration in Azurefunction/startup.cs. which I didn't explicitly add right now.

@srinaath
Copy link
Contributor

Awesome @luhan2017 .. Adding my README commits to this PR too. Once added I think we can request a rereview and merge it

Srinaath Ravichandran added 4 commits May 12, 2020 12:26
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

Readme updated

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
@srinaath
Copy link
Contributor

README updated and update.sh script to run bfdialog tool on Mac/Win added. PR ready for rereview

srinaath and others added 2 commits May 12, 2020 13:37
Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>
@srinaath srinaath requested review from srinaath and boydc2014 May 12, 2020 20:44
boydc2014
boydc2014 previously approved these changes May 13, 2020
Copy link
Contributor

@boydc2014 boydc2014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looks good to me

srinaath
srinaath previously approved these changes May 13, 2020
@a-b-r-o-w-n a-b-r-o-w-n dismissed stale reviews from srinaath and boydc2014 via 1aa2b98 May 13, 2020 18:38
@a-b-r-o-w-n a-b-r-o-w-n merged commit 76cc7c3 into master May 13, 2020
@a-b-r-o-w-n a-b-r-o-w-n deleted the luhan/customActionSample branch May 13, 2020 19:18
lei9444 pushed a commit to lei9444/BotFramework-Composer-1 that referenced this pull request Jun 15, 2021
* Custom Action Sample

* Update resultProperty type

* fix the displayed title of customized action (microsoft#2951)

* Update the Custom Action to a seperated solution

* update

* azure readme

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

Readme updated

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

* Appednignmultiplydialog.schema

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

* Removed whitespace

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

* Fixed typo

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

* More readme updates

Signed-off-by: Srinaath Ravichandran <srravich@microsoft.com>

Co-authored-by: zeye <2295905420@qq.com>
Co-authored-by: Srinaath Ravichandran <srravich@microsoft.com>
Co-authored-by: Srinaath Ravichandran <srinaath27@gmail.com>
Co-authored-by: Andy Brown <asbrown002@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants