public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext executionContext)
        {
            log.LogInformation("Entity Search Custom Skill: C# HTTP trigger function processed a request.");

            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array."));
            }

            string bingApiKey = Environment.GetEnvironmentVariable(bingApiKeySetting, EnvironmentVariableTarget.Process);

            WebApiSkillResponse response = await WebApiSkillHelpers.ProcessRequestRecordsAsync(skillName, requestRecords,
                                                                                               async (inRecord, outRecord) => {
                var entityName = inRecord.Data["name"] as string;
                string uri     = bingApiEndpoint + "?q=" + Uri.EscapeDataString(entityName) + "&mkt=en-us&count=10&offset=0&safesearch=Moderate";

                IEnumerable <BingEntity> entities =
                    await WebApiSkillHelpers.Fetch <BingEntity>(uri, "Ocp-Apim-Subscription-Key", bingApiKey, "entities.value");

                ExtractTopEntityMetadata(entities, outRecord.Data);
                outRecord.Data["entities"] = entities;
                return(outRecord);
            });

            return(new OkObjectResult(response));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext executionContext)
        {
            log.LogInformation("Geo Point From Name Custom skill: C# HTTP trigger function processed a request.");

            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array."));
            }

            string azureMapsKey = Environment.GetEnvironmentVariable(azureMapsKeySetting, EnvironmentVariableTarget.Process);

            WebApiSkillResponse response = await WebApiSkillHelpers.ProcessRequestRecordsAsync(skillName, requestRecords,
                                                                                               async (inRecord, outRecord) => {
                var address = inRecord.Data["address"] as string;
                string uri  = azureMapsUri + "?api-version=1.0&query=" + Uri.EscapeDataString(address);

                IEnumerable <Geography> geographies =
                    await WebApiSkillHelpers.Fetch <Geography>(uri, "X-ms-client-id", azureMapsKey, "results");

                if (geographies.FirstOrDefault() is Geography mainGeoPoint)
                {
                    outRecord.Data["mainGeoPoint"] = new {
                        Type        = "Point",
                        Coordinates = new double[] { mainGeoPoint.Position.Lon, mainGeoPoint.Position.Lat }
                    };
                }
                outRecord.Data["results"] = geographies;
                return(outRecord);
            });

            return(new OkObjectResult(response));
        }