private IMessageActivity BuildDirectLineMessage(IDialogContext context, Response response) { IMessageActivity activity = context.MakeMessage(); activity.Locale = TranslationUtil.GetDefaultLocale(activity.Locale); activity.Text = JsonConvert.SerializeObject(response); return(activity); }
private async Task <IMessageActivity> BuildDirectLineMessage(IDialogContext context, Response response) { JsonResponse jsonResponse = new JsonResponse(response); // Set jsonResponse jsonResponse.ConversationResult = JsonConvert.DeserializeObject <Dictionary <string, string> >( await TranslationUtil.ReverseFromSpanishTranslation( JsonConvert.SerializeObject(GetConversationSummaryDictionary()), TranslationUtil.GetDefaultLocale(_info.Locale))); jsonResponse.Intent = _context.Intent; jsonResponse.Entities = _context.Entities; // Set message IMessageActivity message = BuildMessage(context); message.Text = JsonConvert.SerializeObject(jsonResponse); return(message); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { HttpResponseMessage response; string originalLocale = TranslationUtil.GetDefaultLocale(activity.Locale); try { // Ensure spanish await TranslationUtil.EnsureSpanishTranslation(activity); _channelId = activity.ChannelId; if (!string.IsNullOrEmpty(activity.ServiceUrl)) { _connector = new ConnectorClient(new Uri(activity.ServiceUrl)); } // Get username _userName = GetUserNameOrDefault(activity); if (activity.Type == ActivityTypes.Message) { // Go to MainDialog var dialogInfo = new DialogInfo(activity.ChannelId, _userName, originalLocale); await Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync(activity, () => new MainLUISDialog(dialogInfo)); } else { await HandleSystemMessage(activity); } response = Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { var telemetryClient = new TelemetryClient(); telemetryClient.TrackException(ex); response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException.ToString()); } return(response); }
private IMessageActivity BuildDefaultMessage(IDialogContext context, Response response) { IMessageActivity activity = context.MakeMessage(); activity.Locale = TranslationUtil.GetDefaultLocale(activity.Locale); // Set message activity.Text = response.Message; if (response.EndConversation && _context.SurveyCompleted) { foreach (var question in _context.Questions) { var answer = question.Answer; if (!string.IsNullOrEmpty(answer)) { activity.Text += $"\n{question.Subject}: {answer}. "; } } } return(activity); }
private async Task SendWelcomeMessage(Activity activity) { Activity message; string locale = TranslationUtil.GetDefaultLocale(activity.Locale); // Ensure original language var welcomeMessage = await TranslationUtil.ReverseFromSpanishTranslation(string.Format(AlexaBotframework.BotFrameworkBot.Dialogs.MainLUISDialog.Helpers.Constants.Messages.Welcome, _userName), locale); if (_channelId.Contains(Helpers.Constants.Channels.DirectLine)) { var botResponse = new Dialogs.MainLUISDialog.Models.JsonResponse(new Response(welcomeMessage)); botResponse.Intent = ""; var text = JsonConvert.SerializeObject(botResponse); message = activity.CreateReply(text, locale); } else { message = activity.CreateReply(welcomeMessage, locale); } await _connector.Conversations.ReplyToActivityAsync(message); }
private async Task <IMessageActivity> BuildDefaultMessage(IDialogContext context, Response response) { IMessageActivity message = BuildMessage(context); // Set message message.Text = response.Message; // Conversation summary if (response.EndConversation && _context.CurrentIntentType != IntentType.NotReady && _flowType == FlowType.Normal) { message.Text = await TranslationUtil.ReverseFromSpanishTranslation(GetConversationSummary(), TranslationUtil.GetDefaultLocale(_info.Locale)); } return(message); }