Versions Compared

Key

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

...

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

...

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


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

  3. We will now convert the Flow Chart Workflow into a BotFlow. Click on the Properties tab of the workflow Workflow and change the WorkflowType property to BotFlow.


  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.

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




  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.

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


...

  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.

    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.


  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.

    Code Block
    const string PROMPT_TEMPLATEID = "CreatePersonBotFlowTemplate";

  12. Link the following library with the using statement.

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


  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;
    			}
            }


...

  1. Click on the Compile (tick) button in WFS 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 provided above 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 print the Botflow using the EmpowerID Web UI. Instructions to publish WFS 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.

    Image Removed


    Image Added


Insert excerpt
IL:External Stylesheet
IL:External Stylesheet
nopaneltrue

...