Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

...

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.

    Image RemovedImage Added

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

    Image Removed

    We will now convert the Flow Chart Workflow into a BotFlow. Click on the Properties tab of the Workflow and change the WorkflowType property to BotFlow.
    Image RemovedSave 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. Insert excerptIL:Folder Structure CalloutIL:Folder Structure CalloutnameFolderStructurenopaneltrueImage Removed

  3. Once you save the BotFlow, the WFS will reload the Activity.

  4. Let’s add an activity. Click on the Activities Tab and Search for SystemCodeActivity. Drag and drop the Activity to the designer window.
    Image RemovedSelect the Activity, click on the Properties tab and change the Name to meaningful. In this example, we renamed it as SetResourceOptions.
    Image RemovedAdd 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.
    Code Block
    using TheDotNetFactory.Framework.BotWF.Common;
    Code Block[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" }, Image Added

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

      Image Added

    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.

      Image Added

    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.

      Image Added

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

    Insert excerpt
    IL:Folder Structure Callout
    IL:Folder Structure Callout
    nameFolderStructure
    nopaneltrue

    Image Added

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

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

    Image Added

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

    Image Added

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

    Image Added

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

    Code Block
    using TheDotNetFactory.Framework.BotWF.Common;

    Code Block
    [TheDotNetFactory.Framework.Common.ActivityEventHandlerPostSharpAttribute()]
            public virtual void Implement(object sender, System.EventArgs e)
            {
    			 //TODO: Implementation goes here!
    
    
    			BotHeroCard botHeroCard = new BotHeroCard
    	            {
    	                Title = "BotRequestAppAndMgmtRolesTitle".ToEidResxString(),
    	          

    new

     

    BotCardAction

     

    {

     

    Type

     

    =

     

    BotActionTypes.ImBack,

     

    Title

    Text = "

    ITShop_Common_ManagementRole

    BotRequestAppAndMgmtRolesDescription".ToEidResxString(),
    

    Value

    	 

    =

      

    "ManagementRole",

      

    }

     

              Buttons = new List<BotCardAction> {
    
    	   

    }

     

                

    }; this.CurrentWorkflow.ResourceOptions.HeroCard = botHeroCard;

    new BotCardAction { Type = BotActionTypes.ImBack, Title = "ITShop_Common_ApplicationRole".ToEidResxString(),  Value = "ApplicationRole" },
    	                new BotCardAction 

    }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.
    Image RemovedPlease make sure that all the activities are connected with lines. The Workflow should look similar to the image below.
    Image RemovedClick on the compile (tick) button to compile the Workflow.
    Image Removed

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

...

  1. { Type = BotActionTypes.ImBack, Title = "ITShop_Common_ManagementRole".ToEidResxString(), Value =  "ManagementRole",  }
    	                   }
    	            };
    
    				this.CurrentWorkflow.ResourceOptions.HeroCard = botHeroCard;
    				
            }

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

    Image Added

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

    Image Added

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

Anchor
PublishBotflowFromChat
PublishBotflowFromChat
Publish & Test BotFlow from EID Chatbot

Insert excerpt
IL:BotFlow Snippets
IL:BotFlow Snippets
namePublishBotFlow
nopaneltrue

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

...

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

      Image Modified

  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.

    Code Block
    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.

    Image Removed

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

    Image Added

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

    Image RemovedImage Added

  11. DoubleRight-click on the 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 to and library in the code view.

    Code Block
    const string PROMPT_TEMPLATEID = "CreatePersonBotFlowTemplate";

    Link the following library with the using statement.

    Code Block
    using TheDotNetFactory.Framework.BotWF.Common;

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

    Code Block
    [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;
    			}
            }

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

    Image Added

  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.

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

    Code Block
     [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;
    			}
            }

Anchor
VerifyBotFlow
VerifyBotFlow
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 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. 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.

    Image Removed

...

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

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

    Image Added

    Insert excerpt
    IL:External Stylesheet
    IL:External Stylesheet
    nopaneltrue

Macrosuite divider macro
dividerWidth100
dividerTypetext
emoji{"id":"smile","name":"Smiling Face with Open Mouth and Smiling Eyes","short_names":["smile"],"colons":":smile:","emoticons":["C:","c:",":D",":-D"],"unified":"1f604","skin":null,"native":"😄"}
textColor#000000
dividerWeight3
labelPositionmiddle
textAlignmentcenter
iconColor#0052CC
fontSizemedium
textRelated Docs
emojiEnabledfalse
dividerColor#DFE1E6
dividerIconbootstrap/CloudsFill

Proactive Bot Message

Adaptive Cards

EmpowerID Chatbot

Publish BotFlow from EID Chatbot