创建意图后未检测到动作和参数

时间:2019-06-18 08:56:00

标签: node.js dialogflow actions-on-google

enter image description here我使用API​​发送与实体的意图,但是设置的实体未显示在对话框流中。...

我试图在'trainingPhrases'中插入'entityType','alias'。

 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,
})

1 个答案:

答案 0 :(得分:0)

您是否也在尝试通过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);

希望这可以为您提供帮助。