Versions Compared

Key

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

...

  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.



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


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

  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 and library in the code view.

    Code Block
    const string PROMPT_TEMPLATEID = "CreatePersonBotFlowTemplate";

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

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

    Image Removed


    Image Added


Insert excerpt
IL:External Stylesheet
IL:External Stylesheet
nopaneltrue

...