Ошибка вызова API диалогового окна с помощью программы npm

Я попытался запустить сценарий, который создает конкретное намерение с помощью API Dialogflow. API включен уже через пару недель.

После того, как я вызвал свой скрипт, я получил следующую ошибку: Ошибка: Dialogflow API ранее не использовался в проекте usable-auth-library или он отключен. Включите его, посетив https://console.developers.google.com/apis/api/dialogflow.googleapis.com/overview?project=usable-auth-library, затем повторите попытку. Если вы недавно включили этот API, подождите несколько минут, чтобы действие распространялось на наши системы, и повторите попытку. в /Users/$USER"/Desktop/node_modules/grpc/src/client.js:554:15 код: 7, метаданные: Метаданные {_internal_repr: {'google.rpc.help-bin': [Array], 'grpc -status-details-bin ': [Массив],' grpc-server-stats-bin ': [Массив]}}}

Вот мой сценарий.

  // Imports the Dialogflow library
const dialogflow = require('dialogflow');

// Instantiates clients
const contextsClient = new dialogflow.ContextsClient();
const intentsClient = new dialogflow.IntentsClient();
projectId="1000-1505-ecom-conx-dev"
projectId="conrad-test"
// The path to identify the agent that owns the created intent.
const agentPath = intentsClient.projectAgentPath(projectId);

// Setup intents for ordering a pizza.

// First of all, let's create an intent that triggers pizza order flow.

// Output contexts for ordering pizza. They are used for matching follow-up
// intents. For pizza ordering intents, a "pizza" output context is used for
// hinting the conversation is about pizza ordering, not beer or something
// else. For the first intent, it returns responses asking users to provide
// size information, with a "size" output context for matching the intent
// asking for the size of the pizza.

// Note that session ID is unknown here, using asterisk.
const accountOutputContexts = [
  {
    name: contextsClient.contextPath(
      projectId,
      '*' /* sessionId */,
      'EComerceAgent'
    ),
    lifespanCount: 5,
  },
];

// The result of the matched intent.
const accountResult = {
  action: '',
  parameters: [
    {
      displayName: 'Account for',
      value: '$application',
      entityTypeDisplayName: '@application',
      mandatory: true,
      prompts: [
        'You need appliation access, please describe for which and which permissions do you need?',
        'Would you like access to jirra?',
        'Would you like access to confluence?',
        'Would you like access to AEM?',
      ],
    },
    {
      displayName: 'user',
      value: '$user',
      entityTypeDisplayName: '@user',
      mandatory: true,
      prompts: ['For wich user'],
      isList: true,
    },
    {
      displayName: 'permission',
      value: '$permission',
      // The API provides a built-in entity type @sys.address for addresses.
      entityTypeDisplayName: 'permission',
      mandatory: true,
      prompts: ['Which permission do you need?'],
    },
  ],
  messages: [
    {
      text: {
        text: [
          'No problem. We will create an account on $application for $user with the following permission: $permission'
        ],
      },
    },
    {
      text: {
        text: [
          'Reply "check" to place your order. Reply "cancel" to cancel ' +
            'your order. You can change your delivery address as well.',
        ],
      },
    },
    {
      quickReplies: {
        title:
          'No problem. We will create an account on $application for $user with the following permissions: $permission', 
        quickReplies: ['Create account', 'Cancel']
      },
      platform: 'PLATFORM_UNSPECIFIED',
    },
  ],
  outputContexts: accountOutputContexts,
};

// The phrases for training the linguistic model.
const accountPhrases = [
  {type: 'TYPE_EXAMPLE', parts: [{text: 'Get  account'}]},
  {type: 'TYPE_EXAMPLE', parts: [{text: 'acction'}]},
  {
    type: 'TYPE_EXAMPLE',
    parts: [
      {text: 'Create an account '},
      {text: 'for', entityType: '@application', alias: 'application'},
      {text: ' '},
      {text: 'for ', entityType: '@user', alias: 'user'},
      {text: 'with the followin permissions ', entityType: '@permission', alias: 'permission'},
    ],
  },
  {
    type: 'TYPE_EXAMPLE',
    parts: [
      {text: "I'd like to have access "},
      {text: 'to', entityType: '@application', alias: 'application'},
    ],
  }
];

// The intent to be created.
const accountIntent = {
  displayName: 'Account',
  events: ['create_account'],
  // Webhook is disabled because we are not ready to call the webhook yet.
  webhookState: 'WEBHOOK_STATE_DISABLED',
  trainingPhrases: accountPhrases,
  mlEnabled: true,
  priority: 500000,
  result: accountResult,
};

const accountRequest = {
  parent: agentPath,
  intent: accountIntent,
};

// Create the pizza intent
intentsClient
  .createIntent(accountRequest)
  .then(responses => {
    console.log('Created account intent:');
    logIntent(responses[0]);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

person Tobias Baumgart    schedule 22.12.2017    source источник


Ответы (1)


Ошибка не совсем понятна, это означает, что вы не авторизованы для доступа к удаленному ресурсу без учетных данных. Вот быстрое решение, которое сработало для меня:

  1. Перейдите к https://console.cloud.google.com/apis/credentials/serviceaccountkey < / а>
  2. Загрузите файл аутентификации json (например, foobar-123.json)
  3. Добавить переменную окружения:

    экспорт GOOGLE_APPLICATION_CREDENTIALS = "/ home / me / secure / foobar-123.json"

И полное руководство и документация здесь: https://cloud.google.com/docs/authentication/getting-started


Я сообщил об этой проблеме: https://github.com/dialogflow/dialogflow-nodejs-client-v2/issues/28

person Ssh-uunen    schedule 13.03.2018