| 47 | const intentsClient = new dialogflow.IntentsClient(); |
| 48 | |
| 49 | async function createIntent() { |
| 50 | // Construct request |
| 51 | |
| 52 | // The path to identify the agent that owns the created intent. |
| 53 | const agentPath = intentsClient.projectAgentPath(projectId); |
| 54 | |
| 55 | const trainingPhrases = []; |
| 56 | |
| 57 | trainingPhrasesParts.forEach(trainingPhrasesPart => { |
| 58 | const part = { |
| 59 | text: trainingPhrasesPart, |
| 60 | }; |
| 61 | |
| 62 | // Here we create a new training phrase for each provided part. |
| 63 | const trainingPhrase = { |
| 64 | type: 'EXAMPLE', |
| 65 | parts: [part], |
| 66 | }; |
| 67 | |
| 68 | trainingPhrases.push(trainingPhrase); |
| 69 | }); |
| 70 | |
| 71 | const messageText = { |
| 72 | text: messageTexts, |
| 73 | }; |
| 74 | |
| 75 | const message = { |
| 76 | text: messageText, |
| 77 | }; |
| 78 | |
| 79 | const intent = { |
| 80 | displayName: displayName, |
| 81 | trainingPhrases: trainingPhrases, |
| 82 | messages: [message], |
| 83 | }; |
| 84 | |
| 85 | const createIntentRequest = { |
| 86 | parent: agentPath, |
| 87 | intent: intent, |
| 88 | }; |
| 89 | |
| 90 | // Create the intent |
| 91 | const [response] = await intentsClient.createIntent(createIntentRequest); |
| 92 | console.log(`Intent ${response.name} created`); |
| 93 | } |
| 94 | |
| 95 | createIntent(); |
| 96 | |