// Send response
        private async Task SendResponse(IDialogContext context, Response response)
        {
            IMessageActivity message;

            // Ensure original translation
            response.Message = await TranslationUtil.ReverseFromSpanishTranslation(response.Message, _info.Locale);

            // Build message
            switch (_info.ChannelId)
            {
            case Constants.Channels.DirectLine:
                message = await BuildDirectLineMessage(context, response);

                break;

            case Constants.Channels.WebChat:
            default:
                message = await BuildDefaultMessage(context, response);

                break;
            }

            // Send message
            await context.PostAsync(message);

            if (response.EndConversation)
            {
                context.EndConversation(EndOfConversationCodes.CompletedSuccessfully);
            }
            else
            {
                context.Wait(MessageReceived);
            }
        }
        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);
        }
        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);
        }
        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);
        }
Example #5
0
        // Send response
        private async Task SendResponse(IDialogContext context, Response response)
        {
            IMessageActivity activity;

            // Ensure original translation
            DiagnosticsUtil.TraceInformation($"Response locale {_info.Info.Locale}");

            response.Message = await TranslationUtil.ReverseFromSpanishTranslation(response.Message, _info.Info.Locale);

            // Build message
            switch (_info.Info.ChannelId)
            {
            case AlexaBotframework.BotFrameworkBot.Helpers.Constants.Channels.DirectLine:
                activity = BuildDirectLineMessage(context, response);
                break;

            default:
                activity = BuildDefaultMessage(context, response);
                break;
            }

            // Send response
            await context.PostAsync(activity);

            // Check end conversation
            if (response.EndConversation)
            {
                DialogResultType resultType = _context.SurveyCompleted ? DialogResultType.Completed : DialogResultType.Suspended;

                context.Done(resultType);
            }
            else
            {
                context.Wait(MessageReceived);
            }
        }