Skip to end of banner
Go to start of banner

Create a BotFlow

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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.

  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 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 WFS 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. Add the following snippet of the code. Double-click on the SetResourceOptions and replace the codes 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;
    				
            }


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


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


  11. Click on the compile (tick) button to compile the Workflow.


In the next section, we will publish and test the Workflow.

Publish & Test BotFlow from EID Chatbot

The EID ChatBot is capable of publishing the BotFlow from the MS-Teams channel. You can upload the .pub file generated from WFS from the MS-Teams channel and publish it in EmpowerID. Please follow the instructions below to publish the Botflow from the Ms-Teams channel.

  1. Click on the Compile (tick) button in WFS to compile the Workflow.

  2. Click on the ▶️ Compile and Publish button and complete the necessary step to publish a Workflow.

  3. Login into your MS-Teams application, Initiate a chat with the Chatbot & Click on the attachment icon.

  4. Select the Upload From My Computer option in the menu, locate the pub file of the BotFlow you built, and Click Open and Send the pub file to upload the Workflow.

  5. The ChatBot will publish the Botflow in the EmpowerID environment.

  6. To test the published Botflow, type the name of the Botflow in the ChatBot in your Ms-Teams. In this example, the Botflow name is ActivatePreApprovedGroupWorkflow.

  7. You will be able to see the Botflow in Action. In this example, we uploaded an ActivatePreApprovedGroupWorkflow BotFlow with a Hero card and two buttons.

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. Resource Selected 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.



  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 Activity and add a method called ValidatePromptForInput in the Validate event.


  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 ShowSearchResult activity and add a method called ValidateShowSearchResults in the Validate event.



  11. Double-click on the PromptForInput Activity to open the code view. Add the following constant to the code.

    const string PROMPT_TEMPLATEID = "CreatePersonBotFlowTemplate";

  12. Link the following library with the using statement.

    using TheDotNetFactory.Framework.BotWF.Common;


  13. 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. The dropdown is shown in an adaptive card. Go here to learn more about binding adaptive cards and how Workflow Studio supports the adaptive card feature.

    [TheDotNetFactory.Framework.Common.ActivityEventHandlerPostSharpAttribute()]
            public virtual void Implement(object sender, TheDotNetFactory.Framework.Workflows.Activities.Bot.BotValidationEventArgs e)
            {
    			var search = this.CurrentWorkflow.CurrentBotRequest.GetData<string>();
    			var elegibility = "PreApproved";
    
    			short? elegibilityType = 1;
    
    			if("PreApproved".Equals(elegibility, StringComparison.OrdinalIgnoreCase))
    				 elegibilityType = 3;
    
    			if(this.CurrentWorkflow.CurrentBotRequest.IsDataOfType<string>() && this.CurrentWorkflow.CurrentBotRequest.GetData<string>().ToLower() == "cancel")
    			{
    				e.ValidationResponse.Result = false;
    				e.ValidationResponse.LeaveConversationFlow = true;
                	e.ValidationResponse.LeaveCapability = this.CurrentWorkflow.BotTemplateService.GetCapabilityTemplate<BotTextMessage>(this.CurrentWorkflow,
                    PROMPT_TEMPLATEID, "cancel_msg", new Dictionary<string, object> { { "TargetPerson", Person.GetCurrentPerson()} });
    				return;
    			}
    
    			if(!this.CurrentWorkflow.CurrentBotRequest.IsDataOfType<string>())
    			{
    				e.ValidationResponse.Result = false;
    				e.ValidationResponse.Capability = new BotTextMessage{Text = "Sorry! Please enter the resource name in string format " };
    				return;
    			}
    
    			var resourceType = this.CurrentWorkflow.ResourceOptions.Result;
    			var properties = new Dictionary<string, object>();
    			int totalCount = 0;
    			var person1 = this.CurrentWorkflow.CurrentPerson;
    
    			AdaptiveCardDataSet dataSet = new AdaptiveCardDataSet
                {
                    TitleProperty = "FriendlyName",
                    Method = "pop",
                    DataSetId = "Items"
                };
    
    			switch(resourceType.ToLower())
    			{
    				case "applicationrole":
    
    		            properties.Add("CardTitle", "Select from search results");
    		            properties.Add("CardLabel", "Select a group");
    					properties.Add("submitbutton", "OK");
    		            properties.Add("cancelbutton", "Cancel");
    
    					var groups = C.GroupView.GetForITShop(null, null, null, null, null, null, person1.PersonGUID, false, null, person1.PersonGUID, elegibilityType,null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, null, 0, Int32.MaxValue, out totalCount);
    
    					if(groups != null && groups.Any())
    					{
    						 dataSet.List = groups;
    						 dataSet.TitleDataProperty = "FriendlyName";
    						 dataSet.ValueProperty = "GroupGUID";
    					}
    
    					break;
    
    				case "managementrole":
    
    		            properties.Add("CardTitle", "Select from search results ");
    		            properties.Add("CardLabel", "Select a ManagementRole");
    					properties.Add("submitbutton", "OK");
    		            properties.Add("cancelbutton", "Cancel");
    
    //					var mRoles = C.ManagementRoleView.GetForITShop(null, null, null, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, false, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, elegibilityType,null, null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, 0, Int32.MaxValue, out totalCount);
    					var mRoles = C.ManagementRoleView.GetForITShop(null, null, null, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, false, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, elegibilityType, null, null, null, null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, null, 0, Int32.MaxValue, out totalCount);
    
    					if(mRoles != null && mRoles.Any())
    					{
    						 dataSet.List = mRoles;
    						 dataSet.TitleDataProperty = "FriendlyName";
    						 dataSet.ValueProperty = "ManagementRoleGUID";
    					}
    
    					break;
    			}
    
    			if(dataSet.List != null && dataSet.List.Count > 0 )
    			{
    			 var cardTemplate = this.CurrentWorkflow.BotTemplateService.GetCardTemplate(this.CurrentWorkflow, "DefaultBotAdaptiveCards", "SearchWithoutDefault", properties, new List<AdaptiveCardDataSet> { dataSet });
    			 this.CurrentWorkflow.ShowSearchResult.CardDataJson = cardTemplate.Data;
    			 this.CurrentWorkflow.ShowSearchResult.CardTemplateJson = cardTemplate.Template;
    			 e.ValidationResponse.Result = true;
    		 	 return;
    			}
    			else
    			{
    			 	e.ValidationResponse.Result = false;
    				e.ValidationResponse.Capability = this.CurrentWorkflow.BotTemplateService.GetCapabilityTemplate<BotChoicePrompt>(this.CurrentWorkflow,
                    PROMPT_TEMPLATEID, "no_record", new Dictionary<string, object> { { "input", search} });
    				return;
    			}
            }


  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.

    using TheDotNetFactory.Framework.BotWF.Common;
    using TheDotNetFactory.Framework.People.Components.Helpers;



     [TheDotNetFactory.Framework.Common.ActivityEventHandlerPostSharpAttribute()]
            public virtual void Implement(object sender, TheDotNetFactory.Framework.Workflows.Activities.Bot.BotValidationEventArgs e)
            {
    			var search = this.CurrentWorkflow.CurrentBotRequest.GetData<string>();
    			var elegibility = "PreApproved";
    
    			short? elegibilityType = 1;
    
    			if("PreApproved".Equals(elegibility, StringComparison.OrdinalIgnoreCase))
    				 elegibilityType = 3;
    
    			if(this.CurrentWorkflow.CurrentBotRequest.IsDataOfType<string>() && this.CurrentWorkflow.CurrentBotRequest.GetData<string>().ToLower() == "cancel")
    			{
    				e.ValidationResponse.Result = false;
    				e.ValidationResponse.LeaveConversationFlow = true;
                	e.ValidationResponse.LeaveCapability = this.CurrentWorkflow.BotTemplateService.GetCapabilityTemplate<BotTextMessage>(this.CurrentWorkflow,
                    PROMPT_TEMPLATEID, "cancel_msg", new Dictionary<string, object> { { "TargetPerson", Person.GetCurrentPerson()} });
    				return;
    			}
    
    			if(!this.CurrentWorkflow.CurrentBotRequest.IsDataOfType<string>())
    			{
    				e.ValidationResponse.Result = false;
    				e.ValidationResponse.Capability = new BotTextMessage{Text = "Sorry! Please enter the resource name in string format " };
    				return;
    			}
    
    			var resourceType = this.CurrentWorkflow.ResourceOptions.Result;
    			var properties = new Dictionary<string, object>();
    			int totalCount = 0;
    			var person1 = this.CurrentWorkflow.CurrentPerson;
    
    			AdaptiveCardDataSet dataSet = new AdaptiveCardDataSet
                {
                    TitleProperty = "FriendlyName",
                    Method = "pop",
                    DataSetId = "Items"
                };
    
    			switch(resourceType.ToLower())
    			{
    				case "applicationrole":
    
    		            properties.Add("CardTitle", "Select from search results");
    		            properties.Add("CardLabel", "Select a group");
    					properties.Add("submitbutton", "OK");
    		            properties.Add("cancelbutton", "Cancel");
    
    					var groups = C.GroupView.GetForITShop(null, null, null, null, null, null, person1.PersonGUID, false, null, person1.PersonGUID, elegibilityType,null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, null, 0, Int32.MaxValue, out totalCount);
    
    					if(groups != null && groups.Any())
    					{
    						 dataSet.List = groups;
    						 dataSet.TitleDataProperty = "FriendlyName";
    						 dataSet.ValueProperty = "GroupGUID";
    					}
    
    					break;
    
    				case "managementrole":
    
    		            properties.Add("CardTitle", "Select from search results ");
    		            properties.Add("CardLabel", "Select a ManagementRole");
    					properties.Add("submitbutton", "OK");
    		            properties.Add("cancelbutton", "Cancel");
    
    //					var mRoles = C.ManagementRoleView.GetForITShop(null, null, null, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, false, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, elegibilityType,null, null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, 0, Int32.MaxValue, out totalCount);
    					var mRoles = C.ManagementRoleView.GetForITShop(null, null, null, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, false, null, this.CurrentWorkflow.CurrentPerson.PersonGUID, elegibilityType, null, null, null, null, null, null, null, string.IsNullOrWhiteSpace(search)||string.Equals(search, "all", StringComparison.OrdinalIgnoreCase)? null :search, null, 0, Int32.MaxValue, out totalCount);
    
    					if(mRoles != null && mRoles.Any())
    					{
    						 dataSet.List = mRoles;
    						 dataSet.TitleDataProperty = "FriendlyName";
    						 dataSet.ValueProperty = "ManagementRoleGUID";
    					}
    
    					break;
    			}
    
    			if(dataSet.List != null && dataSet.List.Count > 0 )
    			{
    			 var cardTemplate = this.CurrentWorkflow.BotTemplateService.GetCardTemplate(this.CurrentWorkflow, "DefaultBotAdaptiveCards", "SearchWithoutDefault", properties, new List<AdaptiveCardDataSet> { dataSet });
    			 this.CurrentWorkflow.ShowSearchResult.CardDataJson = cardTemplate.Data;
    			 this.CurrentWorkflow.ShowSearchResult.CardTemplateJson = cardTemplate.Template;
    			 e.ValidationResponse.Result = true;
    		 	 return;
    			}
    			else
    			{
    			 	e.ValidationResponse.Result = false;
    				e.ValidationResponse.Capability = this.CurrentWorkflow.BotTemplateService.GetCapabilityTemplate<BotChoicePrompt>(this.CurrentWorkflow,
                    PROMPT_TEMPLATEID, "no_record", new Dictionary<string, object> { { "input", search} });
    				return;
    			}
            }


Verify The BotFlow is Working

  1. Click on the Compile (tick) 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 print the Botflow using the EmpowerID Web UI. Instructions to publish Workflow Studio items using Web UI are provided here.

  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.


  • No labels