Exemple #1
0
        public async Task FindImage(IDialogContext context, LuisResult result)
        {
            EntityRecommendation title;

            if (result.TryFindEntity("pictureobject", out title))
            {
                var selImg = title.Entity;
                var hasil  = await BingImagesHelper.Search(selImg);

                if (hasil != null)
                {
                    context.UserData.TryGetValue <Activity>("Activity", out _message);
                    ConnectorClient connector           = new ConnectorClient(new Uri(_message.ServiceUrl));
                    Activity        replyToConversation = _message.CreateReply($"Gambar: {selImg}");
                    replyToConversation.Recipient   = _message.From;
                    replyToConversation.Type        = "message";
                    replyToConversation.Attachments = new List <Attachment>();
                    List <CardImage> cardImages = new List <CardImage>();

                    foreach (var x in hasil.value)
                    {
                        cardImages.Add(new CardImage(url: x.thumbnailUrl));
                    }

                    List <CardAction> cardButtons = new List <CardAction>();

                    CardAction plButton = new CardAction()
                    {
                        Value = $"https://www.google.co.id/?q={selImg}",
                        Type  = "openUrl",
                        Title = "Cari"
                    };
                    cardButtons.Add(plButton);
                    ThumbnailCard plCard = new ThumbnailCard()
                    {
                        Title    = $"Hasil pencarian {selImg}",
                        Subtitle = "Cari lebih lanjut..",
                        Images   = cardImages,
                        Buttons  = cardButtons
                    };
                    Attachment plAttachment = plCard.ToAttachment();
                    replyToConversation.Attachments.Add(plAttachment);
                    var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
                }

                //await context.PostAsync($"Mencari gambar {selImg}");
            }
            else
            {
                await context.PostAsync("tidak ditemukan jenis gambar");
            }
            context.Wait(MessageReceived);
        }
Exemple #2
0
        public async Task AfterConfirming_FoodSelect(IDialogContext context, IAwaitable <bool> confirmation)
        {
            if (await confirmation)
            {
                var selfood = string.Empty;
                context.UserData.TryGetValue <string>("SelFood", out selfood);
                var hasil = await BingImagesHelper.Search(selfood + " food");

                if (hasil != null)
                {
                    context.UserData.TryGetValue <Activity>("Activity", out _message);
                    ConnectorClient connector           = new ConnectorClient(new Uri(_message.ServiceUrl));
                    Activity        replyToConversation = _message.CreateReply($"Daftar Makanan {selfood}");
                    replyToConversation.Recipient   = _message.From;
                    replyToConversation.Type        = "message";
                    replyToConversation.Attachments = new List <Attachment>();
                    List <CardImage> cardImages = new List <CardImage>();

                    foreach (var x in hasil.value)
                    {
                        cardImages.Add(new CardImage(url: x.thumbnailUrl));
                    }


                    List <CardAction> cardButtons = new List <CardAction>();
                    CardAction        plButton    = new CardAction()
                    {
                        Value = $"https://www.google.co.id/?q={selfood}",
                        Type  = "openUrl",
                        Title = "Cari"
                    };
                    cardButtons.Add(plButton);
                    HeroCard plCard = new HeroCard()
                    {
                        Title    = $"Makanan {selfood}",
                        Subtitle = "Cari lebih lanjut...",
                        Images   = cardImages,
                        Buttons  = cardButtons
                    };
                    Attachment plAttachment = plCard.ToAttachment();
                    replyToConversation.Attachments.Add(plAttachment);
                    var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
                }

                //await context.PostAsync($"Ok, mencari makanan {selfood}");
            }
            else
            {
                await context.PostAsync("Ok! tidak jadi mencari makanan!");
            }
            context.Wait(MessageReceived);
        }