簡體   English   中英

如何通過對話流中的代碼創建意圖?

[英]How to create the intent via code in dialogflow?

我是 dialogflow 的初學者,試圖通過代碼創建意圖和上下文,但我無法實現它。這是我正在使用的代碼,我也參考了以下鏈接但沒有幫助,

https://cloud.google.com/dialogflow/es/docs/how/manage-intents#create_intent

但出現以下錯誤: 無法在當前環境中檢測到項目 ID。


    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

從屏幕截圖來看,您似乎是在本地計算機上運行它。 該錯誤消息表明未設置指向您的憑據的環境變量。

有關如何設置該環境的信息,請參閱庫文檔的開始之前部分。 其中一個步驟包括通過下載憑據和設置環境變量以指向它們來設置身份驗證 這還將設置您正在使用的項目 ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM