public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext executionContext)
        {
            log.Info("C# HTTP trigger function processed a request.");
            string skillName = executionContext.FunctionName;

            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(req.CreateErrorResponse(HttpStatusCode.BadRequest, $"{skillName} - Invalid request record array."));
            }
            dynamic obj = requestRecords.First().Data.First().Value;

            string val = await MakeRequest(obj);

            ContentModerator     mod    = JsonConvert.DeserializeObject <ContentModerator>(val);
            WebApiResponseRecord output = new WebApiResponseRecord();

            output.RecordId    = requestRecords.First().RecordId;
            output.Data["PII"] = mod.PII;
            WebApiSkillResponse resp = new WebApiSkillResponse();

            resp.Values = new List <WebApiResponseRecord>();
            resp.Values.Add(output);
            return(req.CreateResponse(HttpStatusCode.OK, resp));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext executionContext)
        {
            log.Info("C# HTTP trigger function processed a request.");
            string skillName = executionContext.FunctionName;

            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(req.CreateErrorResponse(HttpStatusCode.BadRequest, $"{skillName} - Invalid request record array."));
            }
            dynamic obj = requestRecords.First().Data.First().Value;

            if (obj.Length > 1024)
            {
                obj = obj.Substring(0, 1024);
            }

            string val = await MakeRequest(obj);

            ContentModerator mod = JsonConvert.DeserializeObject <ContentModerator>(val);

            bool requiresModeration = false;

            //Jon Dobrzeniecki helped with the code below, since may 2019 the CM API isn't returning the PII section if there is no data for it
            if (mod.PII != null)
            {
                if (mod.PII.Email.Length > 0)
                {
                    requiresModeration = true;
                }
                if (mod.PII.Address.Length > 0)
                {
                    requiresModeration = true;
                }
                if (mod.PII.IPA.Length > 0)
                {
                    requiresModeration = true;
                }
                if (mod.PII.Phone.Length > 0)
                {
                    requiresModeration = true;
                }
            }
            WebApiResponseRecord output = new WebApiResponseRecord();

            output.RecordId     = requestRecords.First().RecordId;
            output.Data["text"] = requiresModeration;

            WebApiSkillResponse resp = new WebApiSkillResponse();

            resp.Values = new List <WebApiResponseRecord>();
            resp.Values.Add(output);
            return(req.CreateResponse(HttpStatusCode.OK, resp));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext executionContext)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");

                string skillName = executionContext.FunctionName;

                IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);
                if (requestRecords == null)
                {
                    return(req.CreateErrorResponse(HttpStatusCode.BadRequest, $"{skillName} - Invalid request record array."));
                }
                log.Info($"Content Moderator : {requestRecords.ToString()}");
                dynamic obj = requestRecords.First().Data.First().Value;
                log.Info($"Content Moderator : {obj.ToString()}");

                string val = await MakeRequest(obj);

                ContentModerator     mod    = JsonConvert.DeserializeObject <ContentModerator>(val);
                WebApiResponseRecord output = new WebApiResponseRecord();
                output.RecordId = requestRecords.First().RecordId;
                if (mod.PII.Email.Length > 0)
                {
                    output.Data["PII"] = mod.PII.Email.FirstOrDefault().Detected;
                }
                else
                {
                    output.Data["PII"] = null;
                }
                WebApiSkillResponse resp = new WebApiSkillResponse();
                resp.Values = new List <WebApiResponseRecord>();
                resp.Values.Add(output);
                return(req.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (System.Exception ex)
            {
                log.Info(ex.StackTrace);
            }
            return(null);
        }