Create a 7 quest. & answer Alexa skill - node.js

I'm trying to figure out the best way to create a skill that allows a user to answer questions within a skill. Here's the flow...
Alexa open 'skill'
Alexa: How many planets are in the solar system?
User:
Code: collect response and store to a db
Alex: ask Question 2
User:
Code: collect response and store to a db.
I'm stuck on how to collect the answer (the voice response) from the user and then move to the next question in the queue? I do know how to save records to a db.
Does anyone know of any good examples i can follow?

For each of the pieces of data that you want the user to supply, you should set those up as a "slot". Use the new skill builder tool to set up the intent, the slots that go with it, and the prompts for those slots.
You can then "delegate" the dialog to Alexa who will prompt the user for each slot value in turn, and you'll get a request to your skill code with all the slots populated once she is done. There's detailed documentation here which I hope will help https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/dialog-interface-reference but for me, once I understood that I needed a slot per answer, I was able to follow the documentation and get my skill working.

Related

Dialogflow Fulfillment cannot do dynamic quiz chatbot

I hope you're all having a good day.
I'm trying to make a dynamic quiz chatbot in dialogflow.
So, I have a user saying "Let's play a game". It'll then go to the intent and go into fulfillment. The fulfillment will then go into a method and get a list of dynamic questions from my database. There could be any number of questions. So, the bot will ask the first question and then it will wait for the user's answer and see if it's correct. Then it will ask the next question.
So the bot will firstly ask a question, However, I'm stuck at the part where the user will give an answer. Because I have no idea how to get the bot to listen to the user's answer after asking the first question, and go back into the right fulfillment method.
Because if the user answers with "blue", how will the chatbot know that the user is answering a question instead of just randomly saying blue?
You need to make use of contexts.
When the intent is invoked and it fetch the list of questions from your database, you will also set an output-context.
Then you will have to create one more intent which will be invoked when user is giving an answer. In this intent you will set same context in input-context which you have earlier set in output-context.
This way, Dialogflow will know that user is giving an answer, not just randomly saying some words.
Context is the key in conversations.

Basic Concept of Chatbot using Wit.ai

I am trying to create a chatbot application where user can create their own bot like Botengine. After going through google I saw I need some NLP api to process user's query. As per wit.ai basic example I can set and get data. Now I am confused, How I am going to create a botengine?
So as far I understand the flow, Here is an example for pizza delivery:-
User will enter a welcome message i.e - Hi, Hello ...
Welcome reply will be saved by bot owner in my database.
User will enter some query, then I will hit wit.ai API to process that query. Example :- Users query is "What kind of pizza's available in your store" and wit.ai will respond with the details of intent "pizza_type"
Then I will search for the intent return by wit in my database.
So, is that the right flow to create a chatbot? Am I in the right direction? Could anyone give me some link or some example so I can go through it. I want to create this application using nodejs. I have also found some example in node-wit, but can't find how I will implement this.
Thanks
What you need is webhook. You need to call different API's based on the user intent. I believe you can distinguish between different intents using parameters available in request. Check this out - Creating nodejs webhook for dialogflow

How to get user's first name using alexa skills kit in Node?

Say I want to respond with "Okay xxx" or something of the sort without account linking.
You could try asking the users's name in the first session, and then record it as a session attribute to access later. I recommend going through the Alexa tutorials found here: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
Saving session attributes is covered under "Persisting Skill Attributes through DynamoDB."
Hope that helps somewhat.

How to verify a user's pin when they open the skill (LaunchRequest)

I am having some problems with my Alexa skill. I would like the dialogue to go like this:
User: 'Alexa, open party'
Alexa: 'Hello, what is your four digit secret pin?'
User: '1234'
Alexa: 'Confirmed, what can I help you with?'
But I am confused on how to structure this. I need to take the user's pin and verify it in my codebase. I know you cant get dialogue delegation to work inside of the LaunchRequest. The LaunchRequest can not be customized, so I cannot add slots to it. I can't find any other suggestions/examples on the internet. Has anyone done this before or are there any suggestions?
Amazon supports account linking as the method to connect users with their other accounts. This allows users to log into their other account using OAuth at the time the skill is installed. While it may be possible to determine a user based on the session object userid, it may be difficult to get such a skill published.
It turns out that you can not delegate slot collection to Alexa within the LaunchRequest, because it is not part of a valid response type for LaunchRequest.
My Initial logic was:
User says 'Alexa, open party'
Alexa Skill calls LaunchRequest. (At this point I need to ask the user for their pin by delegating Alexa to do slot colleciton)
In the LaunchRequest, immidiately respond with this.emit(':getPinIntent'); where getPinIntent is another intent existing in my Alexa Skill. The above code is what I saw on the internet for how to call another intent without the user having to provoke using voice.
getPinIntent gets called and immediately it checks to see if all the required slots are filled (i.e. if the slot PIN has a value). If they are not and dialogState !== 'COMPLETED' then I delegate the slot collection to Alexa.
The above step (#4) is where things go wrong. Because delegation is not a valid response type for LaunchRequest's, there is no field dialogueState which is required for delegation to Alexa. The Alexa Request is still a LaunchRequest instead of an Intent request because the user did not invoke the intent by saying something to Alexa.
In conclusion this is not a valid way of completing a dialogue where upon launch the user is asked for a pin and then can reply by only saying that pin, visualized below:
User: "Alexa, open party"
Alexa: "What is your pin" (alexa never gets here, because of #4 and #5 above)
User: "one two three four"
Alexa: "Confirmed, what can I help you with?"
If I have made any mistakes or wrong assumptions please let me know.
My current logic has now changed. If you do not use the Skill Builder Beta you can have a slot exist as an utterance for one of your intents. So I now have getPinIntent with a slot called {PIN} and an utterance in the form of {PIN}. This lets the above type of conversation happen because when the user says his or her pin back ("one two three four") it starts the getPinIntent where I can then continue OR delegate the dialogue to Alexa because for IntentRequest dialog is a valid response type.
The only problem I have now is that because I am not using the Skill Builder Beta I can not (or have not found a way) to add Dialogue Models to/inside of my Intent Schema. I have tried copying the JSON text from the Skill Builder Beta into my Intent Schema after adding the correct Dialogue Model, but this always results in build errors.
So now I can complete the user's pin authentication and respond with a "How can I help", but the IntentRequest that comes after that may require delegation to Alexa for slots, and this would cause a crash because without the Skill Builder Beta I am unable to add the appropriate dialogue models for Alexa to use during delegated slot collection.

Alexa Node Skill Questions / Prompts

So after scavenging the web, I am unable to find an answer to my problem.
Basically, I want to produce the following result in Alexa, and I want to know if its possible and the direction I should be looking in on how to achieve.
Skill / Intent Init
"Hey Alexa.. ask to find a restaurant near me"
Prompt
"What's your favorite cuisine?"
Response
"Italian"
Prompt
"Are you looking to spend a lot of money?"
Response
"No"
The intent logic goes somewhere in the middle of this
"Okay I found a restaurant near you called
This looks like a fairly standard Alexa custom skill. Most of the Alexa examples and tutorials would show you how to do this. I suggest looking at the Amazon developer site for their Alexa custom skill examples and tutorials, or just searching on "Alexa tutorial".
You will collecting 3 bits of information:
The user's location
The type of food
Expensive
These will need to be persisted between questions, so look at examples that either use a database to store the info (DynamoDB is about the easiest to use) or that persist information in the session object (this would be my recommendation).
You can either ask the user for their location using the built in city slot type, or obtain the address of the alexa device using the device address API.
Good luck. I hope this helps give you some pointers on how/where to start.

Resources