首页 > 解决方案 > 创建意图后未检测到操作和参数

问题描述

在此处输入图像描述我使用 API 发送带有实体的意图,但设置的实体未显示在对话框流中......

我试图将“entityType”、“别名”插入“trainingPhrases”。

 trainingPhrases: [
    {
      type: 'EXAMPLE',
      parts: [
        {
          text: intent.question,
          entityType: '@pizza',
          alias: 'pizza',
        },
      ],
    },

…………

const parameter1 = [
  {
    displayName: 'pizza',
    value: 'pizza',
    entityTypeDisplayName: '@pizza',
    mandatory: true,
  },
]
// TODO
await this.intentsClient.batchUpdateIntents({
  parent: intentParent,
  languageCode,
  intentBatchInline: {
    intents: this.intents,
  },
  parameters: parameter1,
})

标签: node.jsdialogflow-esactions-on-google

解决方案


您是否也尝试通过 API 创建实体?

我也通过 API 执行此操作(创建实体 + 创建意图,但不是批量):

创建实体:

exports.createEntity = async function(entityId, tags) {
    let aTags = [];
    for (var i = 0; i < tags.length; i++) {
        let tTags = {};
        let aSyn = [];
        aSyn.push(tags[i].text);

        tTags['value'] = tags[i].text;
        tTags['synonyms'] = aSyn;
        aTags.push(tTags);
    }
    const entityType = {
        displayName: entityId,
        kind: 'KIND_MAP',
        entities: aTags
    };

    const entityRequest = {
        parent: agentPath,
        entityType: entityType
    };

    const responses = await entitiesClient.createEntityType(entityRequest);
    console.log(`Intent ${responses[0].name} created`);
};

这就是我之后创建意图的方式:

// The path to identify the agent that owns the created intent.
const agentPath = intentsClient.projectAgentPath(projectId);

const trainingPhrases = [];

const part = {
    text: tag1.text,
    entityType: '@' + entityId,
    alias: entityId,
};

const part1 = {
    text: tag2.text,
    entityType: '@' + entityId,
    alias: entityId,
};

const partX = {
    text: "news about ",
};

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

const trainingPhrase1 = {
    type: 'EXAMPLE',
    parts: [part1]
};

const trainingPhrase2 = {
    type: 'EXAMPLE',
    parts: [partX, part]
};

const trainingPhrase3 = {
    type: 'EXAMPLE',
    parts: [partX, part1]
};

trainingPhrases.push(trainingPhrase);
trainingPhrases.push(trainingPhrase1);
trainingPhrases.push(trainingPhrase2);
trainingPhrases.push(trainingPhrase3);

const parameter = {
    displayName: entityId + "x1",
    entityTypeDisplayName: '@' + entityId,
    value: tag1.text,
};

const parameter1 = {
    displayName: entityId + "x2",
    entityTypeDisplayName: '@' + entityId,
    value: tag2.text,
};

const messageText = {
    text: 'messageText',
};

const message = {
    text: messageText,
};

const intent = {
    displayName: entityId,
    trainingPhrases: trainingPhrases,
    parameters: [parameter, parameter1],
};

const createIntentRequest = {
    parent: agentPath,
    intent: intent,
};

// Create the intent
const responses = await intentsClient.createIntent(createIntentRequest);

希望这可以以某种方式帮助你。


推荐阅读