How can i pass parameters through NodeJS request? I would like to pass, for example, the name from my code and dialogflow automatically answer with a response which contains the parameters i passed, as "Hi $name".
Mine actual request:
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: languageCode,
},
},
};
EDIT 4 [index.js], this is new right code After the answer
const projectId = 'your-project-id';
const sessionId = 'session-id';
const query = 'your-query';
const languageCode = 'your-language';
const j = require("./structjson.js"); //download It from the answer
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient({keyFilename: './THIS-IS-RIGHT.json'});
// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
async function request() {
const contextClient = new dialogflow.ContextsClient({ keyFilename: './your-path-to-file.json' });
const contextData = {
name: contextClient.contextPath(projectId, sessionId, 'your-context'),
parameters: j.jsonToStructProto({ name: 'John' }),
lifespanCount: 1
};//An example for the name
const context = await contextClient.createContext({
parent: sessionPath,
context: contextData
});
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode
}
},
queryParams: {
contexts: context // You may want to add the other contexts here
}
};
const result = await sessionClient.detectIntent(request);
console.log(result);
}
request();