[英]How to create the intent via code in dialogflow?
我是 dialogflow 的初學者,試圖通過代碼創建意圖和上下文,但我無法實現它。這是我正在使用的代碼,我也參考了以下鏈接但沒有幫助,
https://cloud.google.com/dialogflow/es/docs/how/manage-intents#create_intent
function main(
projectId = 'trainer-gulw',
displayName = 'intent_001',
trainingPhrasesParts = [
'Hello, What is weather today?',
'How is the weather today?',
],
messageTexts = ['Rainy', 'Sunny']
) {
const dialogflow = require('@google-cloud/dialogflow');
// Instantiates the Intent Client
const intentsClient = new dialogflow.IntentsClient();
async function createIntent() {
// Construct request
// The path to identify the agent that owns the created intent.
const agentPath = intentsClient.projectAgentPath(projectId);
const trainingPhrases = [];
trainingPhrasesParts.forEach(trainingPhrasesPart => {
const part = {
text: trainingPhrasesPart,
};
// Here we create a new training phrase for each provided part.
const trainingPhrase = {
type: 'EXAMPLE',
parts: [part],
};
trainingPhrases.push(trainingPhrase);
});
const messageText = {
text: messageTexts,
};
const message = {
text: messageText,
};
const intent = {
displayName: displayName,
trainingPhrases: trainingPhrases,
messages: [message],
};
const createIntentRequest = {
parent: agentPath,
intent: intent,
};
// Create the intent
const [response] = await intentsClient.createIntent(createIntentRequest);
console.log(`Intent ${response.name} created`);
}
createIntent();
// [END dialogflow_create_intent]
}
TIA
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.