上传Intent功能Dialogflow V2 [英] Upload Intent function Dialogflow V2
问题描述
我正在尝试开发一个API来将意图上传到 Dialogflow
V2。我尝试过下面的代码片段,但是如果尝试与 Dialogflow
进行通信,它确实可以正常工作(检测意图)并从 Dialogflow
用于查询。
I am trying to develop an API to upload the intent to Dialogflow
V2. I have tried below snippet, which it is not working however if trying to communicate with Dialogflow
it does work (detect intent)and does get a reply from the Dialogflow
for queries.
允许
我是& ADMIN> SERVICE ACCOUNTS> DIALOGFLOW ADMIN
I AM & ADMIN > SERVICE ACCOUNTS > DIALOGFLOW ADMIN
ERROR
错误:7 PERMISSION_DENIED:'projects / dexter-47332 / agent'上的IAM权限'dialogflow.entityTypes.create'被拒绝。
Error: 7 PERMISSION_DENIED: IAM permission 'dialogflow.entityTypes.create' on 'projects/dexter-47332/agent' denied.
博客/参考
- Dialogflow简便的授权方式
- https://github.com/dialogflow/dialogflow-nodejs-client-v2/blob/master/samples/resource.js# L26
- https://www.npmjs.com / package / dialogflow
- https://开发人员.google.com / apis-explorer /
- https://cloud.google.com/docs/authentication/production
- Dialogflow easy way for authorization
- https://github.com/dialogflow/dialogflow-nodejs-client-v2/blob/master/samples/resource.js#L26
- https://www.npmjs.com/package/dialogflow
- https://developers.google.com/apis-explorer/
- https://cloud.google.com/docs/authentication/production
//------- keys.json (test 1)
{
"type": "service_account",
"project_id": "mybot",
"private_key_id": "123456asd",
"private_key": "YOURKEY",
"client_email": "yourID@mybot.iam.gserviceaccount.com",
"client_id": "098091234",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/yourID%40mybot.iam.gserviceaccount.com"
}
//--------------------- ** (test 2) ** ---------
let privateKey = 'key';
let clientEmail = "email";
let config = {
credentials: {
private_key: privateKey,
client_email: clientEmail
}
}
function createEntityTypes(projectId) {
// [START dialogflow_create_entity]
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// ******** Instantiates clients (Test 1)********
const entityTypesClient = new dialogflow.EntityTypesClient({
'keyFilename': './keys.json'
});
const intentsClient = new dialogflow.IntentsClient({
'keyFilename': './keys.json'
});
// ******** Instantiates clients (Test 2)********
const entityTypesClient = new dialogflow.EntityTypesClient(config);
const intentsClient = new dialogflow.IntentsClient(config);
// The path to the agent the created entity type belongs to.
const agentPath = intentsClient.projectAgentPath(projectId);
const promises = [];
// Create an entity type named "size", with possible values of small, medium
// and large and some synonyms.
const sizeRequest = {
parent: agentPath,
entityType: {
displayName: 'test',
kind: 'KIND_MAP',
autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED',
entities: [{
value: 'small',
synonyms: ['small', 'petit']
},
{
value: 'medium',
synonyms: ['medium']
},
{
value: 'large',
synonyms: ['large', 'big']
},
],
},
};
promises.push(
entityTypesClient
.createEntityType(sizeRequest)
.then(responses => {
console.log('Created size entity type:');
logEntityType(responses[0]);
})
.catch(err => {
console.error('Failed to create size entity type ----->:', err);
})
);
}
createEntityTypes(projectId);
推荐答案
您可以使用JWT(JSON Web令牌)对服务帐户进行身份验证,例如示例
You can use JWT(JSON Web Tokens) for authenticating with service accounts like in this example
const serviceAccount = { }; // JSON key contents {"type": "service_account",...
const serviceAccountAuth = new google.auth.JWT({
email: serviceAccount.client_email,
key: serviceAccount.private_key,
scopes: 'https://www.googleapis.com/auth/calendar'
});
有关Google API的更多OAuth2.0范围,您可以看到完整列表此处。
For more OAuth2.0 scopes for Google APIs you can see the full list here.
这篇关于上传Intent功能Dialogflow V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!