private async Task <DialogTurnResult> CheckCarPredictionAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { if (!(bool)stepContext.Result) { // User said "yes" so we will be prompting for the age. // WaterfallStep always finishes with the end of the Waterfall or with another dialog, here it is a Prompt Dialog. var promptOptions = new PromptOptions { Prompt = MessageFactory.Text(_settings.WrongAnswer), //RetryPrompt = MessageFactory.Text("The value entered must be greater than 0 and less than 150."), }; _logger.LogInformation(LoggingEvents.CheckCarPredictionAsync, $"wrong prediction, ask for input"); return(await stepContext.PromptTypingAsync(nameof(TextPrompt), promptOptions, 1000, cancellationToken)); } else { _logger.LogInformation(LoggingEvents.CheckCarPredictionAsync, $"correct prediction"); await stepContext.SendTypingAsync(MessageFactory.ContentUrl("https://media.giphy.com/media/ckeHl52mNtoq87veET/giphy.gif", "image/gif"), 500, cancellationToken); var carModel = new CarModel { Brand = (string)stepContext.Values["brand"], Name = (string)stepContext.Values["model"], }; var imageBytes = (List <(byte[], string)>)stepContext.Values["vehicleImages"]; await _inventoryService.AddVehicle(carModel, imageBytes, cancellationToken : cancellationToken); await stepContext.SendTypingAsync(_settings.CorrectAnwer, 1000, cancellationToken); return(await stepContext.NextAsync(string.Empty, cancellationToken)); } }
private async Task ProcessSampleQnAAsync(ITurnContext turnContext, CancellationToken cancellationToken) { _logger.LogInformation("ProcessSampleQnAAsync"); var results = await _botServices.SampleQnA.GetAnswersAsync(turnContext); if (results.Any()) { if (turnContext.Activity.Text.ToString() == "ryuk" || turnContext.Activity.Text.ToString() == "豪哥") { await turnContext.SendActivityAsync(MessageFactory.ContentUrl("https://i.imgur.com/2V5ScbX.jpg", "image/jpg")); } else if (turnContext.Activity.Text.ToString() == "爛") { await turnContext.SendActivityAsync(MessageFactory.ContentUrl("https://i.imgur.com/wwkjcC4.jpg", "image/jpg")); await turnContext.SendActivityAsync(MessageFactory.ContentUrl("https://i.imgur.com/HqQegnt.jpg", "image/jpg")); await turnContext.SendActivityAsync(MessageFactory.ContentUrl("https://i.imgur.com/xY3RtxX.jpg", "image/jpg")); } else if (results.First().Answer.Contains("mp4")) { await turnContext.SendActivityAsync(MessageFactory.ContentUrl("http://i.imgur.com/ZNIBbnV.gif", "image/gif")); } else { await turnContext.SendActivityAsync(MessageFactory.Text(results.First().Answer), cancellationToken); } } else { await turnContext.SendActivityAsync(MessageFactory.Text("抱歉,資料庫找不到答案"), cancellationToken); } }
private static async Task ResultsStepSearch(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next) { await dc.Context.SendActivity("Je recherche une destination qui pourrait vous intéresser, merci de patienter."); var state = dc.Context.GetUserState <UserTravelState>(); var travels = await TravelService.SearchTravelsAsync(state.Continent, state.Activities); var travel = travels.FirstOrDefault(); if (travel == null) { state.CurrentTravelId = null; await dc.Prompt("ActionPrompt", "Désolé, je n'ai trouvé aucune destination. Voulez-vous lancer une nouvelle recherche ?"); } else { state.CurrentTravelId = travel.Id; var activity = MessageFactory.ContentUrl(travel.MainImage.Url, "image/jpg", text: $"J'ai trouvé une destination : {travel.Days} jours pour {travel.Desc}"); await dc.Context.SendActivity(activity); await Task.Delay(500); await dc.Prompt("ActionPrompt", "Voulez-vous réserver cette destination ?"); } }
public void ContentUrl() { string text = Guid.NewGuid().ToString(); string ssml = Guid.NewGuid().ToString(); string uri = $"https:// { Guid.NewGuid().ToString()}"; string contentType = MediaTypeNames.Image.Jpeg; string name = Guid.NewGuid().ToString(); IMessageActivity message = MessageFactory.ContentUrl(uri, contentType, name, text, ssml); Assert.AreEqual(message.Text, text, "Message Text does not match"); Assert.AreEqual(message.Type, ActivityTypes.Message, "Incorrect Activity Type"); Assert.IsTrue(message.Attachments.Count == 1); Assert.IsTrue(message.Attachments[0].Name == name, "Incorrect Attachment1 Name"); Assert.IsTrue(message.Attachments[0].ContentType == contentType, "Incorrect contentType"); Assert.IsTrue(message.Attachments[0].ContentUrl == uri, "Incorrect Uri"); }
public void ContentUrl() { var text = Guid.NewGuid().ToString(); var ssml = Guid.NewGuid().ToString(); var inputHint = InputHints.ExpectingInput; var uri = $"https://{Guid.NewGuid().ToString()}"; var contentType = MediaTypeNames.Image.Jpeg; var name = Guid.NewGuid().ToString(); var message = MessageFactory.ContentUrl(uri, contentType, name, text, ssml, inputHint); Assert.Equal(message.Text, text); Assert.Equal(message.Type, ActivityTypes.Message); Assert.Equal(message.InputHint, inputHint); Assert.Equal(message.Speak, ssml); Assert.True(message.Attachments.Count == 1); Assert.True(message.Attachments[0].Name == name, "Incorrect Attachment1 Name"); Assert.True(message.Attachments[0].ContentType == contentType, "Incorrect contentType"); Assert.True(message.Attachments[0].ContentUrl == uri, "Incorrect Uri"); }
public void ContentUrlNull(string url, string contentType) { Assert.Throws <ArgumentNullException>(() => MessageFactory.ContentUrl(url, contentType)); }
public void ContentUrlNull(string url, string contentType) { MessageFactory.ContentUrl(url, contentType); Assert.Fail("Exception not thrown"); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { TelemetryClient telemetry = new TelemetryClient(); if (turnContext.Activity.Type == ActivityTypes.Message) { string activityJson = JsonConvert.SerializeObject(turnContext.Activity); string input = turnContext.Activity.Text; telemetry.TrackTrace("Activity - " + activityJson); ManageApiClient client = GetApiClient(); var parts = Regex.Matches(input, @"[\""].+?[\""]|[^ ]+") .Cast <Match>() .Select(m => m.Value) .ToList(); string command = parts[0].ToLower(); switch (command) { case "createticket": { var ticket = await client.CreateTicket(parts[3], parts[1], (Thoughtpost.ConnectWise.Manage.Models.SeverityEnum) System.Enum.Parse(typeof(Thoughtpost.ConnectWise.Manage.Models.SeverityEnum), parts[2])); string url = _configuration.GetSection("ConnectWise")["TicketUrl"]; url = url.Replace("###", ticket.Id.ToString()); var reply = MessageFactory.ContentUrl( url, @"text/html", @"Ticket #" + ticket.Id.ToString() + " - " + ticket.Summary, @"Ticket #" + ticket.Id.ToString() + " was created successfully."); await turnContext.SendActivityAsync(reply, cancellationToken); } break; case "getticket": { var ticket = await client.GetTicket(System.Int32.Parse(parts[1])); string url = _configuration.GetSection("ConnectWise")["TicketUrl"]; url = url.Replace("###", ticket.Id.ToString()); string lastUpdate = ticket.Info["lastUpdated"]; System.DateTime dtUpdate = DateTime.Parse(lastUpdate); StringBuilder sb = new StringBuilder(); sb.AppendLine($"**Ticket #{ticket.Id} - {ticket.Summary}**"); sb.AppendLine(""); sb.AppendLine($"**Status: ** {ticket.Status.Name}"); sb.AppendLine(""); sb.AppendLine($"**Severity: ** {ticket.Severity.Value.ToString()}"); sb.AppendLine(""); sb.AppendLine($"**Last Updated: ** {dtUpdate.ToString()}"); sb.AppendLine(""); sb.AppendLine($"**Contact: ** {ticket.ContactName} ({ticket.ContactEmailAddress})"); sb.AppendLine(""); sb.AppendLine($"Click here for the complete ticket: [Link]({url})"); var reply = MessageFactory.Text(sb.ToString()); await turnContext.SendActivityAsync(reply, cancellationToken); } break; default: { } break; } } else { await turnContext.SendActivityAsync( MessageFactory.Text($"Sorry, I didn't understand that."), cancellationToken); } }