private ConversationResponseBody CreateConversationResponseFromLastActivity(IEnumerable <Activity> activities, ITurnContext context) { var activity = activities != null && activities.Any() ? activities.Last() : null; if (!SecurityElement.IsValidText(activity.Text)) { activity.Text = SecurityElement.Escape(activity.Text); } var response = new ConversationResponseBody(); var userStorage = new JObject { { "UserId", context.TurnState["GoogleUserId"].ToString() } }; response.UserStorage = userStorage.ToString(); if (activity?.Attachments != null && activity.Attachments.FirstOrDefault(a => a.ContentType == SigninCard.ContentType) != null) { response.ExpectUserResponse = true; response.ResetUserStorage = null; response.ExpectedInputs = new ExpectedInput[] { new ExpectedInput() { PossibleIntents = new PossibleIntent[] { new PossibleIntent() { Intent = "actions.intent.SIGN_IN", InputValueData = new InputValueData() { type = "type.googleapis.com/google.actions.v2.SignInValueSpec" } }, }, InputPrompt = new InputPrompt() { RichInitialPrompt = new RichResponse() { Items = new Item[] { new SimpleResponse() { Content = new SimpleResponseContent() { TextToSpeech = "PLACEHOLDER" } } } } } } }; return(response); } if (!string.IsNullOrEmpty(activity?.Text)) { var simpleResponse = new SimpleResponse { Content = new SimpleResponseContent { DisplayText = activity.Text, Ssml = activity.Speak, TextToSpeech = activity.Text } }; var responseItems = new List <Item> { simpleResponse }; // Add Google card to response if set AddCardToResponse(context, ref responseItems, activity); // Add Media response to response if set AddMediaResponseToResponse(context, ref responseItems, activity); if (activity.InputHint == null || activity.InputHint == InputHints.AcceptingInput) { activity.InputHint = ShouldEndSessionByDefault ? InputHints.IgnoringInput : InputHints.ExpectingInput; } // check if we should be listening for more input from the user switch (activity.InputHint) { case InputHints.IgnoringInput: response.ExpectUserResponse = false; response.FinalResponse = new FinalResponse() { RichResponse = new RichResponse() { Items = responseItems.ToArray() } }; break; case InputHints.ExpectingInput: response.ExpectUserResponse = true; response.ExpectedInputs = new ExpectedInput[] { new ExpectedInput() { PossibleIntents = new PossibleIntent[] { new PossibleIntent() { Intent = "actions.intent.TEXT" }, }, InputPrompt = new InputPrompt() { RichInitialPrompt = new RichResponse() { Items = responseItems.ToArray() } } } }; var suggestionChips = AddSuggestionChipsToResponse(context, activity); if (suggestionChips.Any()) { response.ExpectedInputs.First().InputPrompt.RichInitialPrompt.Suggestions = suggestionChips.ToArray(); } break; default: break; } } else { response.ExpectUserResponse = false; } return(response); }
private DialogFlowResponseBody CreateDialogFlowResponseFromLastActivity(IEnumerable <Activity> activities, ITurnContext context) { var activity = activities != null && activities.Any() ? activities.Last() : null; var response = new DialogFlowResponseBody() { Payload = new ResponsePayload() { Google = new PayloadContent() { RichResponse = new RichResponse(), ExpectUserResponse = !ShouldEndSessionByDefault } } }; if (!string.IsNullOrEmpty(activity?.Text)) { var simpleResponse = new SimpleResponse { Content = new SimpleResponseContent { DisplayText = activity.Text, Ssml = activity.Speak, TextToSpeech = activity.Text } }; var responseItems = new List <Item> { simpleResponse }; // Add Google card to response if set AddCardToResponse(context, ref responseItems, activity); // Add Media response to response if set AddMediaResponseToResponse(context, ref responseItems, activity); response.Payload.Google.RichResponse.Items = responseItems.ToArray(); // If suggested actions have been added to outgoing activity // add these to the response as Google Suggestion Chips var suggestionChips = AddSuggestionChipsToResponse(context, activity); if (suggestionChips.Any()) { response.Payload.Google.RichResponse.Suggestions = suggestionChips.ToArray(); } if (context.TurnState.ContainsKey("systemIntent")) { var optionSystemIntent = context.TurnState.Get <ISystemIntent>("systemIntent"); response.Payload.Google.SystemIntent = optionSystemIntent; } // check if we should be listening for more input from the user switch (activity.InputHint) { case InputHints.IgnoringInput: response.Payload.Google.ExpectUserResponse = false; break; case InputHints.ExpectingInput: response.Payload.Google.ExpectUserResponse = true; break; case InputHints.AcceptingInput: default: break; } } else { response.Payload.Google.ExpectUserResponse = false; } return(response); }
private ConversationResponseBody CreateConversationResponseFromLastActivity(IEnumerable <Activity> activities, ITurnContext context) { var activity = activities.Last(); var response = new ConversationResponseBody(); if (!string.IsNullOrEmpty(activity.Text)) { var simpleResponse = new SimpleResponse { Content = new SimpleResponseContent { DisplayText = activity.Text, Ssml = activity.Speak, TextToSpeech = activity.Text } }; var responseItems = new List <Item> { simpleResponse }; // Add Google card to response if set AddCardToResponse(context, ref responseItems, activity); // Add Media response to response if set AddMediaResponseToResponse(context, ref responseItems, activity); // check if we should be listening for more input from the user switch (activity.InputHint) { case InputHints.IgnoringInput: response.FinalResponse = new FinalResponse() { RichResponse = new RichResponse() { Items = responseItems.ToArray() } }; response.ExpectUserResponse = false; break; case InputHints.AcceptingInput: case InputHints.ExpectingInput: response.ExpectedInputs = new ExpectedInput[] { new ExpectedInput() { PossibleIntents = new IntentName[] { new IntentName() { Intent = "actions.intent.TEXT" }, }, InputPrompt = new InputPrompt() { RichInitialPrompt = new RichResponse() { Items = responseItems.ToArray() } } } }; var suggestionChips = AddSuggestionChipsToResponse(context); if (suggestionChips.Any()) { response.ExpectedInputs.First().InputPrompt.RichInitialPrompt.Suggestions = suggestionChips.ToArray(); } response.ExpectUserResponse = true; break; default: break; } } else { response.ExpectUserResponse = false; } return(response); }