예제 #1
0
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req">Webhook request</param>
        /// <returns>Webhook response</returns>
        public override async Task <WebhookResponse> HandleAsync(WebhookRequest req)
        {
            var searchTerm = req.QueryResult.Parameters.Fields["searchterm"].StringValue;

            DialogflowApp.Show($"<div>Searching for pictures of: {searchTerm}</div><div>Please wait...</div>");

            var searchService = CreateSearchClient();
            var query         = CreateSearchQuery(searchService, searchTerm);
            var result        = await query.ExecuteAsync();

            // Store images in state
            var images = result.Items
                         .Select(x => new ConvState.Image {
                Title = x.Title, Url = x.Link
            })
                         .ToList();

            _conversation.State.ImageList = images;

            var imageList = images.Select(x => $"<li><img src=\"{x.Url}\" alt=\"{WebUtility.HtmlEncode(x.Title)}\" style=\"width:200px\" /></li>");

            DialogflowApp.Show($"<ol>{string.Join("", imageList)}</ol>");

            return(new WebhookResponse
            {
                FulfillmentText = $"Found some pictures of: {searchTerm}. Now, select a picture."
            });
        }
예제 #2
0
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req">Conversation request</param>
        /// <returns></returns>
        public override async Task <string> HandleAsync(ConvRequest req)
        {
            var platform = await Platform.InstanceAsync();

            (var spokenDescription, string[] textDescription) = GetDetailedDescription(platform);

            DialogflowApp.Show(string.Join("", textDescription.Select(x => $"<div>{x}</div>")));
            return(DialogflowApp.Tell(spokenDescription));
        }
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req">Webhook request</param>
        /// <returns>Webhook response</returns>
        public override async Task <WebhookResponse> HandleAsync(WebhookRequest req)
        {
            var platform = await Platform.InstanceAsync();

            (var spokenDescription, string[] textDescription) = GetDetailedDescription(platform);

            DialogflowApp.Show(string.Join("", textDescription.Select(x => $"<div>{x}</div>")));
            return(new WebhookResponse {
                FulfillmentText = spokenDescription
            });
        }
예제 #4
0
        public override async Task <WebhookResponse> HandleAsync(WebhookRequest req)
        {
            var searchTerm = req.QueryResult.Parameters.Fields["searchterm"].StringValue;

            DialogflowApp.Show($"<div>Searching for pictures of: {searchTerm}</div><div>Please wait...</div>");

            var searchService = CreateSearchClient();
            var result        = await searchService.Images.SearchAsync(query : searchTerm);

            // Store images in state
            var images = result.Value
                         .Select(x => new ConvState.Image {
                Title = x.Name, Url = x.ThumbnailUrl
            })
                         .ToList();

            conversation.State.ImageList = images;

            var imageList = images.Select(x => $"<li><img src=\"{x.Url}\" alt=\"{WebUtility.HtmlEncode(x.Title)}\" style=\"width:200px\" /></li>");

            DialogflowApp.Show($"<ol>{string.Join("", imageList)}</ol>");


            // var response = new WebhookResponse();
            var message = new Intent.Types.Message();

            message.CarouselSelect = new Intent.Types.Message.Types.CarouselSelect();
            foreach (var image in images)
            {
                var item = new Intent.Types.Message.Types.CarouselSelect.Types.Item();
                item.Title = image.Title;
                var current = new Intent.Types.Message.Types.Image();
                current.ImageUri = image.Url;
                item.Image       = current;

                message.CarouselSelect.Items.Add(item);
            }
            // response.FulfillmentMessages.Add(message);
            // response.FulfillmentText = $"Found some pictures of: {searchTerm}. Now, select a picture.";

            // return response;

            return(new WebhookResponse
            {
                FulfillmentMessages = { message },
                FulfillmentText = $"Found some pictures of: {searchTerm}. Now, select a picture.",
                Source = ""
            });
            // return new WebhookResponse
            // {
            //     FulfillmentText = $"Found some pictures of: {searchTerm}. Now, select a picture."
            // };
        }
예제 #5
0
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public override string Handle(ConvRequest req)
        {
            // Unfocus the image
            _conversation.State.FocusedImage = null;

            // Update state with list of pictures
            var images     = _conversation.State.ImageList;
            var imagesList = images.Select(x => $"<li><img src=\"{x.Url}\" alt=\"{WebUtility.HtmlEncode(x.Title)}\" style=\"width:200px\" /></li>");

            DialogflowApp.Show($"<ol>{string.Join("", imagesList)}</ol>");

            return(DialogflowApp.Tell("OK, looking at all images now."));
        }
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req">Webhook request</param>
        /// <returns>Webhook response</returns>
        public override async Task <WebhookResponse> HandleAsync(WebhookRequest req)
        {
            var errorMessage = ExtractAndValidateParameters(req, out string englishPhrase, out string languageCode);

            if (errorMessage != null)
            {
                DialogflowApp.Show($"<div>{errorMessage}</div>");

                return(new WebhookResponse
                {
                    FulfillmentText = errorMessage
                });
            }

            var client   = TranslationClient.Create();
            var response = await client.TranslateTextAsync(englishPhrase, languageCode, LanguageCodes.English);

            DialogflowApp.Show($"<div>'{englishPhrase}' is '{response.TranslatedText}' in {languageCode}</div>");
            return(new WebhookResponse {
                FulfillmentText = response.TranslatedText
            });
        }
예제 #7
0
        /// <summary>
        /// Handle the Dialogflow intent.
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public override string Handle(ConvRequest req)
        {
            if (!int.TryParse(req.Parameters["index"], out int index))
            {
                // Something went wrong with parsing, index is not a number
                return(DialogflowApp.Tell($"I don't know which picture you're talking about."));
            }

            if (index < 1 || index > _conversation.State.ImageList.Count)
            {
                // Tried to select an out-of-range picture.
                return(DialogflowApp.Tell($"That picture doesn't exist!"));
            }

            // Store the selected image in the state
            var image = _conversation.State.ImageList[index - 1];

            _conversation.State.FocusedImage = image;

            DialogflowApp.Show($"<img src=\"{image.Url}\" alt=\"{WebUtility.HtmlEncode(image.Title)}\" style=\"height:100%;width:100%\" />");

            return(DialogflowApp.Tell($"Picture {index} selected. You can describe, show landmarks or ask whether the image is safe."));
        }
        /// <summary>
        /// Handle the Dialogflow intent.
        /// </summary>
        /// <param name="req">Webhook request</param>
        /// <returns>Webhook response</returns>
        public override WebhookResponse Handle(WebhookRequest req)
        {
            int index = (int)req.QueryResult.Parameters.Fields["index"].NumberValue;

            if (index < 1 || index > _conversation.State.ImageList.Count)
            {
                // Tried to select an out-of-range picture.
                return(new WebhookResponse {
                    FulfillmentText = $"That picture doesn't exist!"
                });
            }

            // Store the selected image in the state
            var image = _conversation.State.ImageList[index - 1];

            _conversation.State.FocusedImage = image;

            DialogflowApp.Show($"<img src=\"{image.Url}\" alt=\"{WebUtility.HtmlEncode(image.Title)}\" style=\"height:100%;width:100%\" />");

            return(new WebhookResponse
            {
                FulfillmentText = $"Picture {index} selected. You can describe, show landmarks or ask whether the image is safe."
            });
        }