protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { Logger.LogInformation("Running dialog with Message Activity."); // Run the Dialog with the new message Activity. await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { // Grab the conversation data var conversationStateAccessors = _conversationState.CreateProperty <ConversationData>(nameof(ConversationData)); var conversationData = await conversationStateAccessors.GetAsync(turnContext, () => new ConversationData()); string utterance = null; // If we need to switch languages if (conversationData.LanguageChangeRequested || conversationData.LanguageChangeDetected) { string language = utterance; var fullWelcomePrompt = _configuration["WelcomeCardTitle"] + ". " + _configuration["WelcomePrompt"]; string detection_re_welcomeMessage = $"{_configuration["LanguageTransitionPrompt"]}\r\n\r\n{fullWelcomePrompt}\r\n\r\n{_configuration["QuestionSegue"]}"; var dectection_re_welcomePrompt = MessageFactory.Text(detection_re_welcomeMessage); var languageChange_re_welcomePrompt = MessageFactory.Text(fullWelcomePrompt); if (conversationData.LanguageChangeDetected) { // Reset this flag conversationData.LanguageChangeDetected = false; // Re-welcome user in their language await turnContext.SendActivityAsync(dectection_re_welcomePrompt, cancellationToken); // Now run the Dialog with the new message Activity so answer will follow the re-welcome prompt. await Dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); } else // then user explicitly requested a language change { // Reset this flag conversationData.LanguageChangeRequested = false; // Re-welcome user in their language await turnContext.SendActivityAsync(languageChange_re_welcomePrompt, cancellationToken); } } else { // Run the Dialog with the new message Activity. await Dialog.RunAsync(turnContext, _conversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) // Run the Dialog with the new message Activity { if (turnContext.Activity.Text.Contains("user1")) { var obj = list_note.ElementAt(0); link = obj.Picture; } if (turnContext.Activity.Text.Contains("guest")) { link = Microsoft.BotBuilderSamples.Dialog.QnAMakerBaseDialog.link; } if (turnContext.Activity.Text.Contains("user2")) { var obj = list_note.ElementAt(1); link = obj.Picture; } if (turnContext.Activity.Text.Contains("user3")) { var obj = list_note.ElementAt(2); link = obj.Picture; } if (turnContext.Activity.Text.Contains("Evaluate")) { Microsoft.BotBuilderSamples.Bots.CustomVisionService.MakePredictionRequest(link); var l1 = Microsoft.BotBuilderSamples.Bots.CustomVisionService.probabilities; var l2 = Microsoft.BotBuilderSamples.Bots.CustomVisionService.tags; string s = l1.Aggregate((a, b) => a + ", " + b) + " - Values - " + l2.Aggregate((a, b) => a + ", " + b); await turnContext.SendActivityAsync("I say that your picture is " + l2.ElementAt(0).ToString() + " and " + l2.ElementAt(1).ToString() + ". Keep going."); // await stepContext.SendActivityAsync(s); //await Dialog.RunAsync(Message.Text(s), ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken); //return await stepContext.SendActivityAsync(Message.Text(s), cancellationToken).ConfigureAwait(false); //return await stepContext.NextAsync(Message.Text(s), cancellationToken).ConfigureAwait(false); } //await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken); await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { // Run the Dialog with the new message Activity. await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); { // preserve user input. var conversation = turnContext.Activity.Text; // make empty local logitems list. TrackConversation logItems = null; // see if there are previous messages saved in storage. try { string[] conversationList = { "ConversationLog" }; logItems = query.ReadAsync <TrackConversation>(conversationList).Result?.FirstOrDefault().Value; } catch { // Inform the user an error occured. await turnContext.SendActivityAsync("Sorry, something went wrong reading your stored messages!"); } // If no stored messages were found, create and store a new entry. if (logItems is null) { // add the current utterance to a new object. logItems = new TrackConversation(); logItems.ConversationList.Add(conversation); // set initial turn counter to 1. logItems.TurnNumber++; // Show user new user message. //await turnContext.SendActivityAsync($"Echo" + turnContext.Activity.Text); // Create Dictionary object to hold received user messages. var changes = new Dictionary <string, object>(); { changes.Add("ConversationLog", logItems); } try { // Save the user message to your Storage. await query.WriteAsync(changes, cancellationToken); } catch { // Inform the user an error occured. await turnContext.SendActivityAsync("Sorry, something went wrong storing your message!"); } } // Else, our Storage already contained saved user messages, add new one to the list. else { // add new message to list of messages to display. logItems.ConversationList.Add(conversation); // increment turn counter. logItems.TurnNumber++; // show user new list of saved messages. //await turnContext.SendActivityAsync($"Echo " + turnContext.Activity.Text); // Create Dictionary object to hold new list of messages. var changes = new Dictionary <string, object>(); { changes.Add("ConversationLog", logItems); }; try { // Save new list to your Storage. await query.WriteAsync(changes, cancellationToken); } catch { // Inform the user an error occured. await turnContext.SendActivityAsync("Sorry, something went wrong storing your message!"); } } } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var txt = turnContext.Activity.Text; dynamic val = turnContext.Activity.Value; // Check if the activity came from a submit action if (string.IsNullOrEmpty(txt) && val != null) { JToken resultToken = JToken.Parse(turnContext.Activity.Value.ToString()); if (null != resultToken["Action"] && "languageselector" == resultToken["Action"].Value <string>()) { var selectedLang = resultToken["choiceset"].Value <string>(); var attachment = Cards.GetCard(selectedLang, CardType.Intro); if (attachment != null) { var reply = MessageFactory.Attachment(attachment); await turnContext.SendActivityAsync(reply, cancellationToken); } else // debug; { //await turnContext.SendActivityAsync(s_ErrorMsg); } } else if (null != resultToken["Consent"] && 1 == resultToken["Consent"].Value <int>()) { var lang = resultToken["Language"].Value <string>(); var attachment = Cards.GetCard(lang, CardType.AfterAgreeing); if (attachment != null) { var reply = MessageFactory.Attachment(attachment); await turnContext.SendActivityAsync(reply, cancellationToken); } else // debug; { //await turnContext.SendActivityAsync(s_ErrorMsg); } } else if (Util.IsRequestingUserFeedback) { if (null != resultToken["helpful"]) { var helpful = resultToken["helpful"].Value <int>(); var language = resultToken["language"].Value <string>(); string msg = ""; if (1 == helpful) { msg = Util.GetMessageAfterFeedbackHelpful(language); } else if (0 == helpful) { msg = Util.GetMessageAfterFeedbackNotHelpful(language); } await turnContext.SendActivityAsync(msg); var question = resultToken["question"].Value <string>(); var answer = resultToken["answer"].Value <string>(); var translatedQuestion = resultToken["translatedQuestion"].Value <string>(); var translatedAnswer = resultToken["translatedAnswer"].Value <string>(); var langRecord = resultToken["language"].Value <string>(); await Util.RecordQuestionAnswerFeedback( BotServices.TableDbConnectionString, question, answer, translatedQuestion, translatedAnswer, helpful, langRecord); } } } else { await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) => // Run the Dialog with the new message Activity. //await turnContext.SendActivityAsync($"Welcome!"); await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { //check what type of message was sent if (turnContext.Activity.Text == null) { await turnContext.SendActivityAsync(MessageFactory.Text(Message.MessageType_Error), cancellationToken); } else { RestartUser(turnContext, cancellationToken); //user definitions foreach (var item in Users.UsersList) { if (item.Id == turnContext.Activity.Recipient.Id) { current_user = item; } } //checking the executable command CheckCommands(turnContext, current_user); //testing process implementation if (Check.Was_test) { //sending the correct answer if (turnContext.Activity.Text.ToLower() == "/prompt") { await send_image.SendRightReply(turnContext, cancellationToken, current_user); await send_image.SendImageAsync(turnContext, cancellationToken, current_user); //check if the user has passed all the questions if (!SendImages.Was_ended) { await send_image.SendButtonAsync(turnContext, cancellationToken, current_user); } SendImages.Was_ended = false; } else { //validation of the answer if (!SendImages.Was_answer) { await send_image.CheckReplyAsync(turnContext, cancellationToken, current_user); } //sending the next question if the previous one was correct if (SendImages.Right_answer) { await send_image.SendImageAsync(turnContext, cancellationToken, current_user); if (!SendImages.Was_ended) { await send_image.SendButtonAsync(turnContext, cancellationToken, current_user); } SendImages.Was_answer = false; SendImages.Was_ended = false; } } } //sending a response from the knowledge base else { if (turnContext.Activity.Text.ToLower() == "/prompt") { await turnContext.SendActivityAsync(MessageFactory.Text(Message.Prompt_Error), cancellationToken); } else { await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); } } } }