Example #1
0
    private async Task <List <CardAction> > PopulateButtonListFromOptionSettingsAsync(OptionSetting optionSetting)
    {
        try
        {
            if (optionSetting.Type == MessageOptionTypes.AzureSearchFacetsOptions)
            {
                var buttonList = new List <CardAction>();

                // perform the facet call to Azure Search with settings value
                string rawAzureFacetResult = await AzureSearchService.GetAzureSearchFacets(optionSetting.Value,
                                                                                           _dialogModel.AzureSearchSettings.HostUrl, _dialogModel.AzureSearchSettings.EndpointKey);

                // Parse Json into AzureSearchFacet structure
                JObject azureFacetResult = JObject.Parse(rawAzureFacetResult);

                // Get a list of the facets. They each include a count and a value property
                JArray parsedfacetArray = (JArray)azureFacetResult["@search.facets"][optionSetting.Value];

                foreach (JObject facetObject in parsedfacetArray.Children <JObject>())
                {
                    var facetName = ExtractJObjectValue(facetObject, "value");
                    buttonList.Add(
                        new CardAction(
                            Microsoft.Bot.Schema.ActionTypes.ImBack,
                            title: facetName,
                            value: facetName
                            )
                        );
                }

                return(buttonList);
            }
            else
            {
                throw new Exception("[DialogMessageHandler] Invalid type value of optionSettings parameter in dialog structure.");
            }
        }
        catch (System.Exception)
        {
            throw;
        }
    }