Create a BotFlow

This tutorial demonstrates how to create a simple Botflow for the EmpowerID Chatbot. BotFlows are similar to the standard workflows and can trigger a workflow in EmpowerID. The purpose of this tutorial is to guide you through the steps for completing a fully functional Botflow, and we will cover the following flow and capabilities.

Final Output of The Tutorial.
  1. Build a Botflow that will display a HeroCard with two buttons to activate the pre-approved Group or Management role. A user can click among provided options button in the Chatbot that will guide them through the activation process of a pre-approved group or a management role. The instructions are in the section Create a Botflow With a Hero Card Output.

  2. Instructions to Publish & Test the BotFlow from EID Chatbot are provided in the section Publish Botflow From EID Chatbot.

  3. Capture User Input and Implement Business Logic to activate pre-approved Group or Management roles. The section Capture User Input and Implement Business Logic covers the following implementation.

    1. Handle the options the user has chosen between provided options button of Group or a Management Role.

    2. Ask the user to input a name or list all Pre-Approved Group or Management roles.

    3. Find the matching Group or Roles or list all if the user types the command "All. "Users will be able to see a card with the Dropdown list of either Group or Roles.

    4. The user will choose an item in the dropdown. Botflow will execute the logic to activate the Group or Management role and provide a Link to the IAM shop to check the status.

  4. Instructions to verify that the Chatbot works in MS Teams are provided in the section Verify The BotFlow is Working.

 

Create a Botflow With a Hero Card Output

This section has basic instructions for creating a BotFlow with a Hero card and buttons to get you started building BotFlow quickly. After this BotFlow is published, following the instructions in the next section, Publish & Test BotFlow from EID Chatbot, you will be able to see a Hero Card similar to the image below.

  1. In the Workspace tree of Solution Explorer, right-click the Package node where you want to create the Workflow and select New BotFlow > Conversation BotFlow from the context menu.

     

  2. In the Workflow designer, the BasicBotFlowTemplate will load with basic activity shapes.

     

  3. Before you move ahead with the development of BotFlow, you will need to clean up the default activity and events added by Botflow.

    1. Delete the three activities (askQuestion1, askQuestion2, and showResponses) from the Botflow. To delete an activity, you can Right-click on the Activity and select the Delete item from the context menu.

       

    2. Delete all three support classes (MyUserData, OnAgeComplete, OnNameComplete). Select the Solution tab and expand the My Support Classes folder in the Code Tree. Right-click on the class file, and from the context menu, select the Delete Item to delete the file. Please make sure all three classes are deleted.

       

    3. Delete the two event handlers (OnAgeComplete and OnNameComplete) generated by the template. Select the Solution tab, expand the Event Handlers folder, Right-Click on the event handler and delete and from the context menu, select the Delete Item to delete the file. Please make sure both event handlers are deleted.

       

       

  4. Save the BotFlow with an appropriate name. Click on the Save icon, provide a File Name in the dialog, and click the Save button. In the screenshot below, we are saving the Workflow with the Name ActivatePreApprovedGroupWorkflow.



     

  5. Once you save the BotFlow, the Workflow Studio will reload the Activity.

  6. Let's add an activity. Click on the Activities Tab and Search for SystemCodeActivity. Drag and drop the Activity to the designer window.

     

  7. Select the Activity, click on the Properties tab and change the Name to meaningful. In this example, we renamed it as SetResourceOptions.

     

  8. Click on the Activities Tab and Search for BotHeroCardActivity. Drag and drop the Activity to the designer window. Please rename it to reflect its purpose. We have renamed it to ResourceOptions.

     

  9. Add the following snippet of the code. Double-click on the SetResourceOptions and replace the code of the Implement method. You will also need to include the "TheDotNetFactory.Framework.BotWF.Common" library with a using statement to use bot features like HeroCard.

    using TheDotNetFactory.Framework.BotWF.Common;

     

    [TheDotNetFactory.Framework.Common.ActivityEventHandlerPostSharpAttribute()] public virtual void Implement(object sender, System.EventArgs e) { //TODO: Implementation goes here! BotHeroCard botHeroCard = new BotHeroCard { Title = "BotRequestAppAndMgmtRolesTitle".ToEidResxString(), Text = "BotRequestAppAndMgmtRolesDescription".ToEidResxString(), Buttons = new List<BotCardAction> { new BotCardAction { Type = BotActionTypes.ImBack, Title = "ITShop_Common_ApplicationRole".ToEidResxString(), Value = "ApplicationRole" }, new BotCardAction { Type = BotActionTypes.ImBack, Title = "ITShop_Common_ManagementRole".ToEidResxString(), Value = "ManagementRole", } } }; this.CurrentWorkflow.ResourceOptions.HeroCard = botHeroCard; }

     

  10. Please make sure that all the activity shapes are connected with lines. The Workflow should look similar to the image below.

  11. Click on the compile button to compile the Workflow.

     

We have now completed the development of a functional ChatBot. In the next section, we will publish and test the Workflow.

Publish & Test BotFlow from EID Chatbot

We have covered the concepts to create a basic Botflow that shows the Hero card output with two buttons. Let's move forward to capture user input and add business logic to the Bot that will activate the Group or Management role.

Capture User Input and Implement Business Logic

In this section, we will look at how we can capture the input of the hero card build in the previous section and add the business logic behind activating the Group or Management Role. In simple terms, now we will handle the click of the button shown in the Hero Card, ask the user to input a name or list all Pre-Approved Group or Management roles, and activate the selected one.

  1. We will add an activity to capture the input provided by the user in the HeroCard. Click on the Activities Tab and Search for SystemCodeActivity. Drag and drop the Activity to the designer window.

  2. Rename the Activity. In this example, you can see it renamed as SetPrompt.

     

  3. Add three new properties to handle the input selected and the command Cancel; we will use this property in the code snippet of step #4 below.

    1. Cancel of type System. Boolean

    2. CancelMessage of type System.String

    3. ResourceSelected of type System.String

      Click on the Properties tab, Right-Click on the workflow name, and select Add New property. Please make sure you have added all three properties following the same instructions.

       

       

  4. Double-click on the SetPrompt Activity and replace the codes of the Implement method. These lines of code are for handling the input provided by the user along with any invalid input and command cancel to exit the Workflow.

    public virtual void Implement(object sender, System.EventArgs e) { var result = this.CurrentWorkflow.ResourceOptions.Result.ToString(); if("ManagementRole".Equals(result, StringComparison.OrdinalIgnoreCase) || "ApplicationRole".Equals(result, StringComparison.OrdinalIgnoreCase)) { this.CurrentWorkflow.ResourceSelected = result; var title = (from item in this.CurrentWorkflow.ResourceOptions.HeroCard.Buttons where item.Value == result select item.Title).FirstOrDefault(); this.CurrentWorkflow.PromptForInput.Text = string.Format("Please enter the name of the {0} you want to activate (enter 'all' to see all).", title); } else if("Cancel".Equals(result, StringComparison.OrdinalIgnoreCase)) { this.CurrentWorkflow.Cancel = true; this.CurrentWorkflow.CancelMessage = "Cancelling. Thank you!"; } else { this.CurrentWorkflow.Cancel = true; this.CurrentWorkflow.CancelMessage = "Invalid input specified. Cancelling.."; } }

     

  5. Click on the Activities Tab and Search for BotTextMessageActivity. Drag and drop the Activity to the designer window.

  6. Rename the Activity. In this example, we have renamed it as PromptForInput. This Activity will ask the user to input the Name of the Group or Management Role to activate.

     

  7. Select the PromptforInput, click on the properties tab, and set the RetryPrompt property. Provide a text to display to a user if the input provided from the user doesn't return any matches of the Group or Management Role.

     

  8. The BotFlow will search for the roles Name the user has provided and display the results in an adaptive card. Click on the Activities Tab and Search for BotAdaptiveCardActivity. Drag and drop the Activity to the designer window.

  9. Rename the Activity to ShowSearchResult.

     

  10. Select the PromptforInput Activity and add a method called ValidatePromptForInput in the Validate event.

     

  11. Right-click and edit the class file you added earlier for PromptForInput Activity to open the code view. In the previous step, we added it as ValidatePromptForInput. Add the following constant and library in the code view.

     

     

  12. Paste the code below in the Implement Method of the PromptForInput. This code snippet will search the roles based on the input provided by the user and list them in a dropdown in an adaptive card. Go here to learn more about binding adaptive cards and how Workflow Studio supports the adaptive card feature.

     

  13. Select the ShowSearchResult activity and add a method called ValidateShowSearchResults in the Validate event.

     

  14. Click on the Activities Tab and Search for SystemCodeActivity. Drag and drop the Activity to the designer window.

  15. Rename the Activity to ProcessRequest.

     

  16. Add a new method in the handler ExecuteCode. In the example below, we are creating the ProcessRequest_ExecuteCode method.

     

  17. Paste the code in the Implement Method. This code snippet handles the business logic to activate the Pre-Approved Group or Management roles and provides a hero card.


     

     

Verify The BotFlow is Working

  1. Click on the Compile button in Workflow Studio to compile the Workflow.

  2. Click on the Compile and Publish button and complete the necessary step to publish a Workflow if you haven't already.

  3. If you have already uploaded the Botflow by following the instructions in the section Publish & Test BotFlow from EID Chatbot, proceed to the next step to test the BotFlow, or else complete the steps provided in that section to publish it. You can also publish the Botflow using the EmpowerID Web UI. Please follow the link here for the Instructions to publish Workflow Studio items using Web UI.

  4. Type the Name of Botflow in your Ms-Teams and follow the instructions of the Chatbot. You should see the output of the Botflow you created.


     

Proactive Bot Message

Adaptive Cards

EmpowerID Chatbot

Publish BotFlow from EID Chatbot