Reputation: 161
Tried to follow the sample code as this
app.intent('intent1', (conv) => {
const lifespan = 5;
const contextParameters = {
color: 'red',
};
conv.contexts.set('context1', lifespan, contextParameters);
// ...
});
app.intent('intent2', (conv) => {
const context1 = conv.contexts.get('context1');
const contextParameters = context1.parameters;
// ...
});
app.intent('intent3', (conv) => {
conv.contexts.delete('context1');
// ...
});
Here is my code...
app.intent('ask_recipe_intent', (conv, {name}) => {
const term = name.toLowerCase();
const termRef = collectionRef.doc(term);
//Set the context to store the parameter information
const lifespan =5;
const contextParameters = {
name: name,
};
conv.contexts.set('name', 5, name);
return termRef.get()
.then((snapshot) => {
const {city, name, count} = snapshot.data();
return termRef.update({count: count+1})
.then(() => {
conv.ask(`Here you go, ${name}, ${city}. ` +
`do you want to check all the Ingredients needed?`);
});
}).catch((e) => {
console.log('error:', e);
conv.close('Sorry, I did not catch you, can you say again or try another word.');
});
});
app.intent('yes_list_ingredient_intent', conv => {
const termRef = conv.contexts.get(name);
const contextParameters = name.parameters;
conv.ask(`The ingredients of ${name} includes ${ingredientall}. ` +
`do you want to add to shopping list or go to steps of cooking?`);
});
app.intent('no_steps2cook_intent', conv => {
conv.contexts.delete(name);
conv.ask(`The steps to cook for ${name} as following ${stepsall}. ` +
`enjoy cooking`);
});
But got "Webhook error (206) Malformed Response"
What's wrong with my code and where can I get more samples to learn except Temperature Converter Trivia which seems to be the older version.
Upvotes: 1
Views: 136
Reputation: 50701
You have several references to a variable name
in your code, such as
const termRef = conv.contexts.get(name);
but nowhere do you define what name
is.
When you set the context, you're setting it to the context that is literally named "name", but you're trying to set it with parameters that are stored in the name
variable, and that isn't defined:
conv.contexts.set('name', 5, name);
I am guessing that the latter is supposed to be something like
conv.contexts.set('name', 5, contextParameters);
since you define contextParameters
, but never use them. And that you mean to call your context "name" since thats the name you use for the name in that call.
Upvotes: 1