# FAQ

This section contains various tips. You might not have access to all the features described here, so don't worry if you don't understand some of the titles!

Agora is not being triggered

Make sure that your scenarios are being ended

I'm designing a trivia game in Dialogflow, how can I keep the score?

In the fullfilments in Dialogflow, you can use the context to serve as a memory for keeping the score. Here is a code example that increases, resets or returns the score depending on the selected intent.

'use strict';
  
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

function reset(agent) {   
    agent.setContext({
    name: 'score',
    lifespan: 20,  // Amount of follow-up intents this context will be kept
    parameters: {'score': 0},
    });
    
    agent.add(`tu veux gagner un point?`);
}

function get_score(agent) {    
    const score_context = agent.getContext('score');
    let score_value = score_context.parameters.score;
    
    agent.add(`Le score final est de ` + score_value);
}

function good_answer(agent) {    
    const score_context = agent.getContext('score');
    const score_value = score_context.parameters.score + 1;
    
    agent.setContext({
    name: 'score',
    lifespan: 20,  // Amount of follow-up intents this context will be kept
    parameters: {'score': score_value},
    });
    
    agent.add(`j'ajoute un, le nouveau score est de ` + score_value);
}

function wrong_answer(agent) {
    const score_context = agent.getContext('score');
    let score_value = score_context.parameters.score;
    //not adding anything
    
    agent.setContext({
    name: 'score',
    lifespan: 20,  // Amount of follow-up intents this context will be kept
    parameters: {'score': score_value},
    });
    
    agent.add(`dommage!`);
}

// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('premiere question', reset);
intentMap.set('premiere question - yes', good_answer);
intentMap.set('premiere question - no', wrong_answer);
intentMap.set('score final', get_score);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});