I want to get input of a parameter in my webhook fulfillment.
Here is the my code:
const bodyParser = require('body-parser')
var request = require('request-promise-native');
const { dialogflow } = require('actions-on-google');
const assistant = dialogflow({
clientId: "30xxxxx08407-rv9kxxxxxxxxuuq8f9ul2eg.apps.googleusercontent.com"
});
module.exports = (app) => {
const logger = console;
assistant.intent('Sales', conv => {
const pcode = agent.parameters['PCODE'];
console.log(pcode)
const token = '3369708919812376';
const serviceID = '502';
const P_STATE_CD = 'ALL';
const P_FO_CD = 'ALL';
const P_DISTT_CD = 'ALL';
const P_DATE = '16/12/2019';
const P_PRD_GROUP = 'UREA';
const P_PERSONAL_NO = '106296';
var data = {"token" : token,"serviceID" : serviceID,"P_STATE_CD" : P_STATE_CD,"P_FO_CD" : P_FO_CD,"P_DISTT_CD" : P_DISTT_CD,"P_DATE" : P_DATE,"P_PRD_GROUP" : P_PRD_GROUP,"P_PERSONAL_NO" : P_PERSONAL_NO };
var sdata = JSON.stringify(data);
const options = {
method: 'POST',
uri: 'http://Webservice/resources/webservice/service' ,
body: JSON.parse(sdata) ,
json: true
}
return request(options)
.then( body => {
var unit = body
console.log(body)
unit.intent = "Sales"
unit.value1 = unit.saleInfo[0].QMTD
unit.value2 = unit.saleInfo[0].QYTD
unit.value3 = unit.saleInfo[0].O_UOM
unit.value4 = null
unit.value5 = null
delete unit.saleInfo
var unit2 = JSON.stringify(unit)
console.log(unit2)
conv.ask(unit2);
})
.catch( err => {
console.error( err );
conv.ask('Something went wrong. What should I do now?');
});
})
I tried with const pcode = agent.parameters.PCODE
but it is not working. Giving me error:
ReferenceError: agent is not defined at assistant.intent.conv (/home/dbalounge/GoogleDF/service.js:15:16) at Function. (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:151:27) at Generator.next () at /home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71 at new Promise () at __awaiter (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12) at Function.handler (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:85:16) at Object. (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/assistant.js:55:32) at Generator.next () at /home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/assistant.js:22:71
agent
is not defined anywhere in your code, that's why you're getting:
ReferenceError: agent is not defined
In any case if you use assistant.parameters
won't work either. Dialogflow intent parameters can be accessed through the second argument of .intent
callback.
assistant.intent('Sales', (conv, params) => {
const pcode = params.PCODE;
/* ... */
})
For more info you can check the docs