* Create an intent. * @param {string} projectId The project to be used * @param {string} displayName Display Name * @param {string} trainingPhrasesParts Training Phrases * @param {string} messageTexts Message Texts
(
projectId = 'YOUR_PROJECT_ID',
displayName = 'YOUR_INTENT_DISPLAY_NAME',
trainingPhrasesParts = [
'Hello, What is weather today?',
'How is the weather today?',
],
messageTexts = ['Rainy', 'Sunny']
)
| 22 | * @param {string} messageTexts Message Texts |
| 23 | */ |
| 24 | function main( |
| 25 | projectId = 'YOUR_PROJECT_ID', |
| 26 | displayName = 'YOUR_INTENT_DISPLAY_NAME', |
| 27 | trainingPhrasesParts = [ |
| 28 | 'Hello, What is weather today?', |
| 29 | 'How is the weather today?', |
| 30 | ], |
| 31 | messageTexts = ['Rainy', 'Sunny'] |
| 32 | ) { |
| 33 | // [START dialogflow_create_intent] |
| 34 | |
| 35 | /** |
| 36 | * TODO(developer): Uncomment the following lines before running the sample. |
| 37 | */ |
| 38 | // const projectId = 'The Project ID to use, e.g. 'YOUR_GCP_ID'; |
| 39 | // const displayName = 'The display name of the intent, e.g. 'MAKE_RESERVATION'; |
| 40 | // const trainingPhrasesParts = 'Training phrases, e.g. 'How many people are staying?'; |
| 41 | // const messageTexts = 'Message texts for the agent's response when the intent is detected, e.g. 'Your reservation has been confirmed'; |
| 42 | |
| 43 | // Imports the Dialogflow library |
| 44 | const dialogflow = require('@google-cloud/dialogflow'); |
| 45 | |
| 46 | // Instantiates the Intent Client |
| 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, |
no test coverage detected