Nodejs-dialogflow: How can i update intent ?

Created on 27 Mar 2020  路  6Comments  路  Source: googleapis/nodejs-dialogflow

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

question dialogflow

All 6 comments

@Strykrol @nnegrey what are the best docs to point folks towards for updating intents? I noticed we removed the samples around this recently (wondering if there's an alternative).

I need to get done,

Create agents,
Create Intents,
Update Intents

bottom of the line i need to give end user to customize the bot with my own interface.

but it was difficult to find a well explained document.

_Get intent is working like below for me, i need to._

async function getIntent() {
    const intentsClient = new dialogflow.IntentsClient(config);
    const projectAgentPath = intentsClient.projectAgentPath(projectId);
    const request = {
      name: 'projects/chat-bot-test-oxhcpn/agent/intents/54f817a6-6ac5-49ae-b63b-5b2367511184',
      languageCode: 'en',
      intentView: 'INTENT_VIEW_FULL'
};

const [response] = await intentsClient.getIntent(request);
return response;

}

We didn't have a sample for updating intents.

Docs page with samples on managing intents is here: https://cloud.google.com/dialogflow/docs/manage-intents#create-intent-nodejs

Though for reference docs, I typically recommend the RPC docs.
Under the Intents service you can find:
UpdateIntent or BatchUpdateIntents

https://cloud.google.com/dialogflow/docs/reference/rpc/google.cloud.dialogflow.v2#intents

Hi @harshan89, You can try the following way.

const main = async (newTrainingPhrases) => {
    const dialogflow = require('dialogflow');

    const intentsClient = new dialogflow.IntentsClient();

    const projectAgentPath = intentsClient.projectAgentPath(['YOUR PROJECT ID']);

    const request = {
        parent: projectAgentPath,
        intentView: 'INTENT_VIEW_FULL'
    }

    const [response] = await intentsClient.listIntents(request);

    const intent = existingIntent; //get the intent that needs to be updated from the [response];

    const trainingPhrases = [];
    let previousTrainingPhrases =
        intent.trainingPhrases.length > 0
            ? intent.trainingPhrases
            : [];

    previousTrainingPhrases.forEach(textdata => {
        newTrainingPhrases.push(textdata.parts[0].text)
    });

    newTrainingPhrases.forEach(phrase => {
        const part = {
            text: phrase
        };

        //Here we create a new training phrase for each provided part.
        const trainingPhrase = {
            type: 'EXAMPLE',
            parts: [part]
        }
        trainingPhrases.push(trainingPhrase);
    });

    intent.trainingPhrases = trainingPhrases;

    const updateIntentRequest = {
        intent: intent,
        intentView: 'INTENT_VIEW_FULL'
    }

    //Send the request for update the intent.
    const result = await intentsClient.updateIntent(updateIntentRequest);
    console.log(result);
}

main(['test']);

Let me know if this works for you.

Hi @harshan89, You can try the following way.

const main = async (newTrainingPhrases) => {
    const dialogflow = require('dialogflow');

    const intentsClient = new dialogflow.IntentsClient();

    const projectAgentPath = intentsClient.projectAgentPath(['YOUR PROJECT ID']);

    const request = {
        parent: projectAgentPath,
        intentView: 'INTENT_VIEW_FULL'
    }

    const [response] = await intentsClient.listIntents(request);

    const intent = existingIntent; //get the intent that needs to be updated from the [response];

    const trainingPhrases = [];
    let previousTrainingPhrases =
        intent.trainingPhrases.length > 0
            ? intent.trainingPhrases
            : [];

    previousTrainingPhrases.forEach(textdata => {
        newTrainingPhrases.push(textdata.parts[0].text)
    });

    newTrainingPhrases.forEach(phrase => {
        const part = {
            text: phrase
        };

        //Here we create a new training phrase for each provided part.
        const trainingPhrase = {
            type: 'EXAMPLE',
            parts: [part]
        }
        trainingPhrases.push(trainingPhrase);
    });

    intent.trainingPhrases = trainingPhrases;

    const updateIntentRequest = {
        intent: intent,
        intentView: 'INTENT_VIEW_FULL'
    }

    //Send the request for update the intent.
    const result = await intentsClient.updateIntent(updateIntentRequest);
    console.log(result);
}

main(['test']);

Let me know if this works for you.

yes this is works for me fine, but there is a problem the property of intent (languageCode) is not working when i update the intent, i have to manage 4 languages so it's important.

Fixed


const intentRequest = {
        parent: projectAgentPath,
        intent: intent,
        languageCode: lang
};

let [response] = await intentsClient.updateIntent(intentRequest)
return response;

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yanniks picture yanniks  路  8Comments

BenjaminHoegh picture BenjaminHoegh  路  7Comments

YrockInnovators picture YrockInnovators  路  4Comments

patrick-zimmermann picture patrick-zimmermann  路  6Comments

daaru00 picture daaru00  路  3Comments