Example #1
0
        public async static void Run([BlobTrigger("kyccontainer/{name}", Connection = "AzureWebJobsStorage")] Stream blob, string name, TraceWriter log)
        {
            try
            {
                log.Info($"Azure blob function triggered for the passport image: {name}");

                // Resolve assembly
                FunctionsAssemblyResolver.StaticInstance();

                // Using AbbyyCloudOCR to extract Passport details
                RestServiceClient restClient = new RestServiceClient();

                // Convert stream into image stream
                MemoryStream streamOut = ImageStream.GetImageStream(blob);
                OcrSdkTask   task      = restClient.ProcessMrz(streamOut);

                // Get Passport details
                AbbyyCloudOCRResponse abbyyCloudOCRResponse = restClient.WaitAndGetAbbyyCloudOCRResponse(task);

                // Using Trulioo API for Passport verification
                Transaction transaction = await Verify.VerifyPassport(abbyyCloudOCRResponse, streamOut);

                // Save the AbbyyCloudOCR response and transaction response into the database
                DataLayer.KYCDbContext.Save(abbyyCloudOCRResponse, transaction);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex, "KYC blob function");
            }
        }
Example #2
0
        public async Task CarPhotoReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            if (message.Attachments != null && message.Attachments.Count > 0)
            {
                var attachment = message.Attachments[0];

                if (attachment.ContentType == "image/png" || attachment.ContentType == "image/jpeg")
                {
                    var contentStream = await ImageStream.GetImageStream(attachment.ContentUrl);

                    JObject json = await CustomVision.GetCustomVisionJson(contentStream);

                    // check is car
                    Boolean isCar = false;
                    foreach (var prediction in json["predictions"])
                    {
                        //var tag = prediction["tagName"];
                        //var percent = decimal.Parse(prediction["probability"].ToString()) * 100;
                        //var percentStr = percent.ToString("0.##");
                        //await context.PostAsync($"{tag} {percentStr}%");

                        var tag     = prediction["tagName"].ToString();
                        var percent = decimal.Parse(prediction["probability"].ToString()) * 100;
                        if (tag == "car" && percent >= 50)
                        {
                            isCar = true;
                            break;
                        }
                    }

                    if (isCar)
                    {
                        foreach (var prediction in json["predictions"])
                        {
                            var tag = prediction["tagName"].ToString();
                            if (tag == "car")
                            {
                                continue;
                            }
                            else
                            {
                                SuggestCarConditionFromModel(tag);

                                this.user.likedCar = this.user.suggestCar3;
                                var outMessage = context.MakeMessage();
                                outMessage.Attachments = new List <Attachment>()
                                {
                                    new HeroCard
                                    {
                                        Title  = this.user.suggestCar3,
                                        Text   = $"จากรูปรถของ{this.user.genderThai} รถยนต์ที่เหมาะสมและใกล้เคียงกับความต้องการของ{this.user.genderThai} คือ {this.user.suggestCar3}",
                                        Images = new List <CardImage> {
                                            new CardImage(this.user.suggestImage3)
                                        },
                                        Buttons = new List <CardAction> {
                                            new CardAction(ActionTypes.OpenUrl, "ข้อมูล", value: this.user.suggestUrl3)
                                        }
                                    }.ToAttachment()
                                };
                                await context.PostAsync(outMessage);

                                var quiz = $"{this.user.genderThai}ชอบรถยนต์คันนี้หรือไม่";
                                PromptDialog.Choice(context, this.OnLikeVisionCarSelected, yesNoOptions, quiz, "ออเจ้าเลือกไม่ถูกต้อง", 3);

                                break;
                            }
                        }
                    }
                    else
                    {
                        await context.PostAsync($"ข้าว่านี่ไม่ใช่รถนะเจ้าคะ โปรดส่งรูปรถให้ข้าเถิดเจ้าค่ะ");

                        context.Wait(CarPhotoReceivedAsync);
                    }
                }
                else
                {
                    await context.PostAsync($"ข้าว่านี่ไม่ใช่รูปนะเจ้าคะ โปรดส่งรูปรถให้ข้าเถิดเจ้าค่ะ");

                    context.Wait(CarPhotoReceivedAsync);
                }
            }
            else
            {
                await context.PostAsync($"ข้าไม่เห็นรูปอะไรเลยเจ้าค่ะ");

                context.Wait(CarPhotoReceivedAsync);
            }
        }
Example #3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            if (message.Attachments != null && message.Attachments.Count > 0)
            {
                var attachment = message.Attachments[0];

                if (attachment.ContentType == "image/png" || attachment.ContentType == "image/jpeg")
                {
                    var contentStream = await ImageStream.GetImageStream(attachment.ContentUrl);

                    dynamic json = await FaceAPI.GetFaceAPIJson(contentStream);

                    if (json.Count > 0)
                    {
                        var face = json[0]["faceAttributes"];
                        this.user.gender = face["gender"].ToString();
                        this.user.age    = decimal.Parse(face["age"].ToString());

                        this.user.smile     = decimal.Parse(face["smile"].ToString());
                        this.user.glasses   = face["glasses"].ToString();
                        this.user.anger     = decimal.Parse(face["emotion"]["anger"].ToString());
                        this.user.eyeMakeup = Convert.ToBoolean(face["makeup"]["eyeMakeup"].ToString());
                        this.user.lipMakeup = Convert.ToBoolean(face["makeup"]["lipMakeup"].ToString());

                        this.user.hair = face["hair"].ToString();
                        this.user.bald = decimal.Parse(face["smile"].ToString());
                        var hairColor = face["hair"]["hairColor"];
                        if (hairColor.Count > 0)
                        {
                            this.user.hairColor = hairColor[0]["color"].ToString();
                        }
                        else
                        {
                            this.user.hairColor = "";
                        }
                        this.user.moustache = decimal.Parse(face["facialHair"]["moustache"].ToString());
                        this.user.beard     = decimal.Parse(face["facialHair"]["beard"].ToString());
                        this.user.emotion   = face["emotion"].ToString();

                        if (this.user.gender == "male")
                        {
                            this.user.genderThai = "ท่านหมื่น";
                        }
                        else
                        {
                            this.user.genderThai = "แม่หญิง";
                        }

                        if (this.user.eyeMakeup || this.user.lipMakeup)
                        {
                            this.user.makeupStr = "ชอบการแต่งตัว";
                        }
                        else
                        {
                            this.user.makeupStr = "เป็นคนง่ายๆ สบายๆ";
                        }

                        if (this.user.smile > 0.0M)
                        {
                            this.user.smileStr = "รักความสนุกสนาน";
                        }
                        else
                        {
                            if (this.user.eyeMakeup || this.user.lipMakeup)
                            {
                                this.user.smileStr = "ชอบความเรียบง่าย";
                            }
                            else
                            {
                                this.user.smileStr = "ชอบความโก้หรู";
                            }
                        }

                        if (this.user.anger > 0.7M)
                        {
                            this.user.angerStr = "ชอบความปราดเปรียว";
                        }
                        else
                        {
                            this.user.angerStr = "";
                        }

                        var quiz = $"ข้าเห็นหน้าออเจ้าแล้ว ออเจ้าเป็น{this.user.genderThai} ใช่หรือไม่";
                        PromptDialog.Choice(context, this.OnGenderSelected, yesNoOptions, quiz, "ออเจ้าเลือกไม่ถูกต้อง", 3);
                    }
                    else
                    {
                        --attempts;
                        await context.PostAsync($"ออเจ้าไม่ได้ส่งรูปใบหน้าของออเจ้ามา ส่งรูปหน้าออเจ้ามาให้ข้าด้วยเถิด");

                        context.Wait(MessageReceivedAsync);
                    }
                }
                else
                {
                    --attempts;
                    await context.PostAsync($"ออเจ้าไม่ได้ส่งรูปใบหน้าของออเจ้ามา ส่งรูปหน้าออเจ้ามาให้ข้าด้วยเถิด");

                    context.Wait(MessageReceivedAsync);
                }
            }
            else
            {
                --attempts;
                await context.PostAsync($"ส่งรูปหน้าออเจ้ามาให้ข้าด้วยเถิด");

                context.Wait(MessageReceivedAsync);
            }

            if (attempts <= 0)
            {
                context.Fail(new TooManyAttemptsException("รูปที่ออเจ้าส่งมาไม่ถูกต้อง"));
            }
        }