1

the function below prints the item and in what quantity that has been ordered

function confirmitem(agent){
    const item = agent.getContext('item'),
    Food = item.parameters.Food, 
    quantity = item.parameters.quantity;
    agent.add('Confirming '+Food+' in a quantity of '+quantity);
}

below is the output context

"outputContexts": [{
    "name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/item",
    "lifespanCount": 4,
    "parameters": {
        "Food": "matooke",
        "Food.original": "matooke",
        "quantity": {
            "number.original": "1",
            "number": 1
        },
        "quantity.original": "1"
    }
},
{
"name": "projects/simple-dialog-wtckcj/agent/sessions/1a459958-2249-5973-9561-5418940b0b22/contexts/itemconfirm",
"lifespanCount": 4,
"parameters": {
    "quantity": {
        "number": 1,
        "number.original": "1"
    },
    "quantity.original": "1",
    "Food": "matooke",
    "Food.original": "matooke"
}
}
]

the actual output is 'Confirming matooke in a quantity of [object Object]'

Prisoner
  • 49,922
  • 7
  • 53
  • 105
Henry
  • 11
  • 4
  • Does this answer your question? [Detecting an undefined object property](https://stackoverflow.com/questions/27509/detecting-an-undefined-object-property) – tbking May 20 '20 at 13:50

1 Answers1

0

The issue is that item.parameters.quantity is an object with a value of

    {
        "number.original": "1",
        "number": 1
    },

When you try to print this, the normal way to print the object is just with "[object Object]", as you've noticed.

You probably want to access the "number" field inside this object with something like item.parmeters.quantity.number. If you wanted to access the "original" value, which is exactly what the user said, you may need to use something like item.parameters["quantity.original"]. You would need to use this indexing method because "quantity.original" contains a period.

Prisoner
  • 49,922
  • 7
  • 53
  • 105