/** * Creates a {@code SpeechletResponse} for the intent and stores the extracted name in the * Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response the given intent */ private SpeechletResponse SetNameInSessionAndSayHello(Intent intent, Session session) { // Get the slots from the intent. var slots = intent.Slots; string speechOutput; if (!slots.Any()) { speechOutput = "I'm sorry, I didn't hear your name. You can tell me your name by saying, my name is Sam"; return BuildSpeechletResponse(intent.Name, speechOutput, false); } // Get the name slot from the list slots. var nameSlot = slots.Keys.Contains(NameSlot) ? slots[NameSlot] : null; // Check for name and create output to user. if (nameSlot != null) { // Store the user's name in the Session and create response. var name = nameSlot.Value; session.Attributes[NameKey] = name; speechOutput = $"Hello {name}, now I can remember your name, you can ask me your name by saying, whats my name?"; } else { // Render an error since we don't know what the users name is. speechOutput = "I'm not sure what your name is, please try again"; } // Here we are setting shouldEndSession to false to not end the session and // prompt the user for input return BuildSpeechletResponse(intent.Name, speechOutput, false); }
public void LogRequest(IntentRequest request, Session session, string resultMessage) { if (request == null) { return; } AlexaSkillsKit.Slu.Intent intent = request.Intent; string intentName = (intent != null) ? intent.Name : null; string intentParam = null; string delimeter = ""; if (request.Intent != null && request.Intent.Slots != null && request.Intent.Slots.Count > 0) { intentParam = ""; foreach (var slot in request.Intent.Slots) { intentParam = intentParam + delimeter + slot.Value.Value; delimeter = " | "; } } if (session.Attributes.ContainsKey("sessionIntentParam")) { intentParam = intentParam + delimeter + "session: " + session.Attributes["sessionIntentParam"] + ""; } LogRequestToDb(AlexaRequestType.IntentRequest, session.Application.Id, session.User.Id, intentName, intentParam, resultMessage); }
/** * Creates a {@code SpeechletResponse} for the intent and stores the extracted name in the * Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response the given intent */ private SpeechletResponse SetNameInSessionAndSayHello(Intent intent, Session session) { // Get the slots from the intent. Dictionary<string, Slot> slots = intent.Slots; // Get the name slot from the list slots. Slot nameSlot = slots[NAME_SLOT]; string speechOutput = ""; // Check for name and create output to user. if (nameSlot != null) { // Store the user's name in the Session and create response. string name = nameSlot.Value; session.Attributes[NAME_KEY] = name; speechOutput = String.Format( "Hello {0}, now I can remember your name, you can ask me your name by saying, whats my name?", name); } else { // Render an error since we don't know what the users name is. speechOutput = "I'm not sure what your name is, please try again"; } // Here we are setting shouldEndSession to false to not end the session and // prompt the user for input return BuildSpeechletResponse(intent.Name, speechOutput, false); }
/** * Creates a {@code SpeechletResponse} for the intent and get the user's name from the Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response for the intent */ private SpeechletResponse GetNameFromSessionAndSayHello(Intent intent, Session session) { string speechOutput = ""; bool shouldEndSession = false; if (!session.Attributes[Session.INTENT_SEQUENCE].Contains("MyNameIsIntent")) { speechOutput = "I'm sorry, you seem to be new here. You can tell me your name by saying, my name is Sam"; return BuildSpeechletResponse(intent.Name, speechOutput, false); } // Get the user's name from the session. var name = session.Attributes.ContainsKey(NAME_KEY) ? session.Attributes[NAME_KEY] : null; // Check to make sure user's name is set in the session. if (!String.IsNullOrEmpty(name)) { speechOutput = String.Format("Your name is {0}, goodbye", name); shouldEndSession = true; } else { // Since the user's name is not set render an error message. speechOutput = "I'm not sure what your name is, you can say, my name is Sam"; } return BuildSpeechletResponse(intent.Name, speechOutput, shouldEndSession); }
/** * Creates a {@code SpeechletResponse} for the intent and get the user's name from the Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response for the intent */ private SpeechletResponse GetNameFromSessionAndSayHello(Intent intent, Session session) { string speechOutput = ""; bool shouldEndSession = false; // Get the user's name from the session. string name = (String)session.Attributes[NAME_KEY]; // Check to make sure user's name is set in the session. if (!String.IsNullOrEmpty(name)) { speechOutput = String.Format("Your name is {0}, goodbye", name); shouldEndSession = true; } else { // Since the user's name is not set render an error message. speechOutput = "I'm not sure what your name is, you can say, my name is Sam"; } return BuildSpeechletResponse(intent.Name, speechOutput, shouldEndSession); }
public IntentRequest(string requestId, DateTime timestamp, Intent intent) : base(requestId, timestamp) { Intent = intent; }