如何运行 dialogflow节点js?
how to run the dialogflow node js?
我仍然对 Dialogflow nodejs 的文档感到困惑,我可以弄清楚吗?
我已阅读此文档 -> https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.sessions/detectIntent
如何测试我的代码并查看我输入的查询结果?
我应该在这个函数
中通过 Axios 做 POST
async function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}
我还是不太清楚,所以我们是否需要在本地也使用 HTTP 请求来检查这个?
我已经按照 Dialogflow nodejs 示例进行操作,但是接下来呢?
它在 google 上说我们必须 POST
POST https://dialogflow.googleapis.com/v2/{session=projects//agent/sessions/}:detectIntent
请求正文位于该函数内的请求变量上,
但我仍然不清楚 dialogflow nodejs 的下一步 运行 该方法
您可以 运行 直接使用 Express 应用程序。只需从您的快速应用程序路由调用此函数,或者您可以调用文件中的给定函数并使用 node <filename.js>
到 运行 代码。确保使用 process.env.GOOGLE_APPLICATION_CREDENTIALS = "<your_json_file_path>";
在路径名中添加 google 云凭据
const sessionClient = new dialogflow.SessionsClient(
// below can be used to set the variable in code itself, if below is not working you can run following in the terminal
//export GOOGLE_APPLICATION_CREDENTIALS="/<path of the json file"
{
keyFilename: "/<path of the json file"
}
);
我仍然对 Dialogflow nodejs 的文档感到困惑,我可以弄清楚吗? 我已阅读此文档 -> https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.sessions/detectIntent
如何测试我的代码并查看我输入的查询结果? 我应该在这个函数
中通过 Axios 做 POSTasync function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}
我还是不太清楚,所以我们是否需要在本地也使用 HTTP 请求来检查这个? 我已经按照 Dialogflow nodejs 示例进行操作,但是接下来呢?
它在 google 上说我们必须 POST POST https://dialogflow.googleapis.com/v2/{session=projects//agent/sessions/}:detectIntent
请求正文位于该函数内的请求变量上, 但我仍然不清楚 dialogflow nodejs 的下一步 运行 该方法
您可以 运行 直接使用 Express 应用程序。只需从您的快速应用程序路由调用此函数,或者您可以调用文件中的给定函数并使用 node <filename.js>
到 运行 代码。确保使用 process.env.GOOGLE_APPLICATION_CREDENTIALS = "<your_json_file_path>";
const sessionClient = new dialogflow.SessionsClient(
// below can be used to set the variable in code itself, if below is not working you can run following in the terminal
//export GOOGLE_APPLICATION_CREDENTIALS="/<path of the json file"
{
keyFilename: "/<path of the json file"
}
);