質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Dialogflow

Dialogflowは、Googleが提供している自然言語対話プラットフォーム。音声入力で自然言語の解析を行ってくれる機能で、対話型アプリを簡単に作成することが可能です。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

0回答

1821閲覧

DialogflowをAPIで操作しようとするとPERMISSION_DENIEDエラーが出る。

ytommy

総合スコア11

Dialogflow

Dialogflowは、Googleが提供している自然言語対話プラットフォーム。音声入力で自然言語の解析を行ってくれる機能で、対話型アプリを簡単に作成することが可能です。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

0クリップ

投稿2020/06/28 22:43

前提・実現したいこと

Node.jsで実装しているプログラムからAPIでDialogflowを呼び出そうとしております。
プログラムを実行すると、PERMISSION_DENIEDエラーが表示されます。

発生している問題・エラーメッセージ

Sending Query: Hello Error: 7 PERMISSION_DENIED: IAM permission 'dialogflow.sessions.detectIntent' on 'projects/xxxx/agent' denied.

該当のソースコード

Javascript

1//Dialogflow 2 3// projectId: ID of the GCP project where Dialogflow agent is deployed 4const projectId = 'xxxx'; 5// sessionId: String representing a random number or hashed user identifier 6const sessionId = '123456789'; 7// queries: A set of sequential queries to be send to Dialogflow agent for Intent Detection 8const queries = [ 9 'Hello' 10] 11// languageCode: Indicates the language Dialogflow agent should use to detect intents 12const languageCode = 'en'; 13 14// Imports the Dialogflow library 15const dialogflow = require('@google-cloud/dialogflow'); 16 17// Instantiates a session client 18const sessionClient = new dialogflow.SessionsClient(); 19 20async function detectIntent( 21 projectId, 22 sessionId, 23 query, 24 contexts, 25 languageCode 26) { 27 // The path to identify the agent that owns the created intent. 28 const sessionPath = sessionClient.projectAgentSessionPath( 29 projectId, 30 sessionId 31 ); 32 33 // The text query request. 34 const request = { 35 session: sessionPath, 36 queryInput: { 37 text: { 38 text: query, 39 languageCode: languageCode, 40 }, 41 }, 42 }; 43 44 if (contexts && contexts.length > 0) { 45 request.queryParams = { 46 contexts: contexts, 47 }; 48 } 49 50 const responses = await sessionClient.detectIntent(request); 51 return responses[0]; 52} 53 54async function executeQueries(projectId, sessionId, queries, languageCode) { 55 // Keeping the context across queries let's us simulate an ongoing conversation with the bot 56 let context; 57 let intentResponse; 58 for (const query of queries) { 59 try { 60 console.log(`Sending Query: ${query}`); 61 intentResponse = await detectIntent( 62 projectId, 63 sessionId, 64 query, 65 context, 66 languageCode 67 ); 68 console.log('Detected intent'); 69 console.log( 70 `Fulfillment Text: ${intentResponse.queryResult.fulfillmentText}` 71 ); 72 // Use the context from this response for next queries 73 context = intentResponse.queryResult.outputContexts; 74 } catch (error) { 75 console.log(error); 76 } 77 } 78} 79executeQueries(projectId, sessionId, queries, languageCode);

試したこと

環境変数GOOGLE_APPLICATION_CREDENTIALSにはダウンロードしたjsonファイルのパスを設定しておりますが、うまくいっていないようです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問