title: How to create shopping cart and calculate total money when using DialogFlow?
body: <p>Recently i've started to create a pizza ordering chat bot with DialogFlow but don't know how to create a shopping cart with it and also calculate total amount order plus total money user have to pay.
  Here's something i've been working on but doesn't work, 'basket' parameters seems to be empty. </p>
  
  <p>here's something to provide you more information about what's happening in my DialogFlow. So i have an intent name " item.confirm.yes " . the script is when a customer ask for pizza, they must fill in 3 values : size, type and quantity in intents </p>
  
  <p>"item.start" - this intent will carry 2 contexts are "item" and "item-confirm" to intents "item.confirm.yes". At this point, if customer confirm their order, "item.confirm.yes" intents will put out context "basket".</p>
  
  <p>Here's some logging about intent "item.confirm.yes"</p>
  
  <p><strong>index json</strong></p>
  
  <pre><code>'use strict';
  
  const functions = require('firebase-functions');
  const {WebhookClient} = require('dialogflow-fulfillment');
  
  process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
  
  exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) =&gt; {
    const agent = new WebhookClient({ request, response });
    console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
    console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
  
    let intentMap = new Map();
  
    function showBasket(agent) {
       if (agent.context.get('basket') != null) {
         const basket = agent.context.get('basket'),
               basketItems = basket.parameters.items,
               itemKeys = Object.keys(basketItems);
  
         var basketOutput = `So far you've got: `;
         for (let i = 0; i &lt; itemKeys.length; i++) {
           let item = basketItems[itemKeys[i]];
           if ((i &lt; 0) &amp;&amp; (i === itemKeys.length - 1)) {
             basketOutput += ` and `;
           }
           else if (i &gt; 0) {
             basketOutput += `, `;
           }
           basketOutput += `${item.amount} ${item.type} in ${item.size}`;
         }
         agent.add(basketOutput);
       }
      else {
        agent.add(`There's nothing in your basket`);
      }
    }
  
    function confirmItem(agent) {
      const item = agent.context.get('item'),
            amount = item.parameters.amount,
            size = item.parameters.size,
            type = item.parameters.type;
  
      var basketContext = {'name': 'basket', 'lifespan':50, 'parameters': {}},
          items = {};
      if (agent.context.get('basket')) {
        items = agent.context.get('basket').parameters.item;
      }
      item[request.body.responseId] = {
        "type": type,
        "size": size,
        "amount": amount
      };
      basketContext.parameters.items = items;
      console.log(JSON.stringfy(basketContext));
      agent.context.set(basketContext);
      agent.add(`Confirming ${amount} ${type} pizza in ${size}. Anything else ?`);
    }
  
  
    intentMap.set('order.showbasket', showBasket);
    intentMap.set('item.confirm.yes', confirmItem);
    agent.handleRequest(intentMap);
  });
  </code></pre>
  
  <p><strong>package json:</strong></p>
  
  <pre><code>{
    "name": "dialogflowFirebaseFulfillment",
    "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
    "version": "0.0.1",
    "private": true,
    "license": "Apache Version 2.0",
    "author": "Google Inc.",
    "engines": {
      "node": "8"
    },
    "scripts": {
      "lint": "eslint --fix \"**/*.js\"",
      "start": "firebase serve --only functions",
      "deploy": "firebase deploy --only functions",
      "test": "npm run lint"
    },
    "dependencies": {
      "actions-on-google": "^2.2.0",
      "firebase-admin": "^5.13.1",
      "firebase-functions": "^2.0.2",
      "dialogflow": "^0.6.0",
      "dialogflow-fulfillment": "^0.5.0"
    }
  }
  </code></pre>
  
  <p>and when i tried to pull out the basket
  <strong>Diagnostic info</strong></p>
  
  <pre><code>{
    "responseId": "bcad0d74-58ae-4f7a-9e00-532ae296b7e6-dd2bbea9",
    "queryResult": {
      "queryText": "basket",
      "parameters": {},
      "allRequiredParamsPresent": true,
      "fulfillmentMessages": [
        {
          "text": {
            "text": [
              ""
            ]
          }
        }
      ],
      "outputContexts": [
        {
          "name": "projects/pizzadelivery-gyahra/agent/sessions/7180f8e2-a871-a1d5-694b-44f8395c6c30/contexts/basket",
          "lifespanCount": 1
        }
      ],
      "intent": {
        "name": "projects/pizzadelivery-gyahra/agent/intents/fef12ceb-ba15-4b84-9a5f-406aa648c5c8",
        "displayName": "order.showbasket"
      },
      "intentDetectionConfidence": 1,
      "diagnosticInfo": {
        "webhook_latency_ms": 4988
      },
      "languageCode": "en"
    },
    "webhookStatus": {
      "code": 4,
      "message": "Webhook call failed. Error: DEADLINE_EXCEEDED."
    },
    "alternativeQueryResults": [
      {
        "queryText": "basket",
        "languageCode": "en"
      }
    ]
  }
  </code></pre>
  
  <p>what happening in itent item.confirm.yes when i ordered one pepperoni pizza large</p>
  
  <pre><code>{
    "responseId": "04942abf-da3c-4074-9b5b-2fcaf97c053a-9aa0e9ed",
    "queryResult": {
      "queryText": "yes",
      "parameters": {},
      "allRequiredParamsPresent": true,
      "fulfillmentText": "Great, anything else ?",
      "fulfillmentMessages": [
        {
          "text": {
            "text": [
              "Great, anything else ?"
            ]
          },
          "platform": "FACEBOOK"
        },
        {
          "text": {
            "text": [
              "Great, anything else ?"
            ]
          }
        }
      ],
      "outputContexts": [
        {
          "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/basket",
          "lifespanCount": 1,
          "parameters": {
            "amount": 1,
            "type": "Pepperoni",
            "size": "large",
            "type.original": "pepperoni",
            "amount.original": "one",
            "size.original": "large"
          }
        },
        {
          "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/item",
          "lifespanCount": 4,
          "parameters": {
            "amount": 1,
            "type": "Pepperoni",
            "size": "large",
            "type.original": "pepperoni",
            "amount.original": "one",
            "size.original": "large"
          }
        },
        {
          "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/item-confirm",
          "lifespanCount": 4,
          "parameters": {
            "size.original": "large",
            "amount": 1,
            "type": "Pepperoni",
            "size": "large",
            "type.original": "pepperoni",
            "amount.original": "one"
          }
        }
      ],
      "intent": {
        "name": "projects/pizzadelivery-gyahra/agent/intents/0723f0a9-9f7e-4c04-a57d-0218c2c3ecf9",
        "displayName": "item.confirm.yes"
      },
      "intentDetectionConfidence": 1,
      "diagnosticInfo": {
        "webhook_latency_ms": 4992
      },
      "languageCode": "en"
    },
    "webhookStatus": {
      "code": 4,
      "message": "Webhook call failed. Error: DEADLINE_EXCEEDED."
    },
    "alternativeQueryResults": [
      {
        "queryText": "yes",
        "outputContexts": [
          {
            "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/basket",
            "lifespanCount": 4,
            "parameters": {
              "size.original": "large",
              "amount": 1,
              "type": "Pepperoni",
              "size": "large",
              "type.original": "pepperoni",
              "amount.original": "one"
            }
          },
          {
            "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/item",
            "lifespanCount": 4,
            "parameters": {
              "amount": 1,
              "type": "Pepperoni",
              "size": "large",
              "type.original": "pepperoni",
              "amount.original": "one",
              "size.original": "large"
            }
          },
          {
            "name": "projects/pizzadelivery-gyahra/agent/sessions/498ae696-5e2e-589e-7402-4fd1b803579f/contexts/item-confirm",
            "lifespanCount": 4,
            "parameters": {
              "size": "large",
              "type.original": "pepperoni",
              "amount.original": "one",
              "size.original": "large",
              "amount": 1,
              "type": "Pepperoni"
            }
          }
        ],
        "languageCode": "en"
      }
    ]
  }
  </code></pre>