public void GetBingImageUrlTest() { BingImageService service = new BingImageService(); DailyChallengeImage image = service.GetBingImageUrl(1); Assert.IsTrue(!string.IsNullOrEmpty(image.ImageText) && !string.IsNullOrEmpty(image.ImageRegion)); }
public async Task LoadImagesAsync() { IsLoading = true; BingImageCollection.Clear(); var list = await BingImageService.GetBingImagesAsync(8); BingImageCollection.AddRange(list); IsLoading = false; }
public async Task StartAsync(IDialogContext context) { await context.PostAsync(Response.SendPicture_Start); try { var image = await BingImageService.GetBestImageAsync(_objectPicture); var reply = context.MakeMessage(); var heroCard = new HeroCard() { Title = $"Bing: '{_objectPicture}'", Subtitle = $"Top image for '{_objectPicture}' query", Images = new List <CardImage> { new CardImage(url: image.ContentUrl) }, Buttons = new List <CardAction> { new CardAction() { Value = image.WebSearchUrl, Type = "openUrl", Title = image.Name } } }; reply.Attachments = new List <Attachment> { heroCard.ToAttachment() }; await context.PostAsync(reply); } catch (Exception ex) { await context.PostAsync($"ERROR: {ex.Message}"); await context.PostAsync(Response.Error); } context.Done <object>(null); }
private async Task <Attachment> GetBingImageChoiceAttachment(int imageIndex) { BingImageService imageService = new BingImageService(); DailyChallengeImage image = imageService.GetBingImageUrl(imageIndex); await tableService.SaveDailyChallengeImage(image); var heroCard = new HeroCard { Title = "Today's Daily Challenge", Subtitle = image.ImageRegion, Text = "Click to choose the image for today or try another image.", Images = new List <CardImage> { new CardImage(image.Url) }, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Choose image", value: "Choose image"), new CardAction(ActionTypes.ImBack, "Try another image", value: "Try another image"), new CardAction(ActionTypes.ImBack, "Switch to Google", value: "Switch to Google") } }; return(heroCard.ToAttachment()); }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var command = stepContext.Result.ToString(); if (command.ToLower().Contains("choose image")) { int imageIndex = await GetImageIndex(stepContext); BingImageService imageService = new BingImageService(); DailyChallengeImage image = await tableService.getDailyChallengeImage(); BingMapService mapService = new BingMapService(Configuration["BingMapsAPI"]); Logger.LogInformation("Image Text: " + image.ImageText); DailyChallengeEntry challengeEntry = await mapService.GetLocationDetails(image.ImageText, Logger); if (challengeEntry == null) { Logger.LogError("Unable to retrieve details of image"); throw new Exception("Unable to retrieve details from Google"); } Logger.LogInformation("Image Response: " + challengeEntry.imageResponse); Logger.LogInformation("Longitude: " + challengeEntry.longitude); Logger.LogInformation("Latitude: " + challengeEntry.latitude); Logger.LogInformation("Latitude: " + challengeEntry.distanceFrom); var dailyChallenge = await tableService.GetDailyChallenge(); dailyChallenge.photoUrl = image.Url; dailyChallenge.text = image.ImageText; dailyChallenge.latitude = challengeEntry.latitude; dailyChallenge.longitude = challengeEntry.longitude; dailyChallenge.extractedLocation = challengeEntry.imageResponse; dailyChallenge.entries = new List <DailyChallengeEntry>(); dailyChallenge.publishedTime = DateTime.Now; dailyChallenge.currentStatus = DailyChallengeStatus.Guessing; await tableService.SaveDailyChallenge(dailyChallenge); IMessageActivity reply = MessageFactory.Attachment(new List <Attachment>()); reply.Attachments.Add(AttachmentHelper.ImageChosen(dailyChallenge.photoUrl)); var activity = (Activity)reply; await stepContext.Context.SendActivityAsync((Activity)reply); return(await stepContext.EndDialogAsync(cancellationToken)); //return await stepContext.ReplaceDialogAsync(nameof(ChallengeGuesserDialog), promptOptions, cancellationToken); } else if (command.ToLower().Contains("try another image")) { int imageIndex = await IncrementAndReturnImageIndex(); } else if (command.ToLower().Contains("switch to google")) { try { var reply = MessageFactory.Attachment(new List <Attachment>()); var attachment = await GetGoogleImageChoiceAttachment(); await UpdateImageSource(ImageSource.Google); reply.Attachments.Add(attachment); } catch (Exception exp) { Logger.LogError(exp, $"Could not set Google Image: {exp.Message} - {exp.StackTrace}", null); throw exp; } } else if (command.ToLower().Contains("switch to bing")) { var reply = MessageFactory.Attachment(new List <Attachment>()); int imageIndex = await GetImageIndex(stepContext); await UpdateImageSource(ImageSource.Bing); var attachment = await GetBingImageChoiceAttachment(imageIndex); // reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments.Add(attachment); } else { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, not sure about that"), cancellationToken); } return(await stepContext.BeginDialogAsync(nameof(MainDialog), null, cancellationToken)); }
public BingImageServiceTests() { // Arrange service = new BingImageService(); }