googleapis / googleapis/google-cloud-node

[Dialogflow] Authenticate with API Key

Open
#4,692 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

Hello,
I want to use dialogflow api within my project (for Gen App chat bot).
But the authentication seems weird.

My server is hosted in Azure and most of third parties I use connect with API Token or API Key.
Here with dialogflow I can't find any documentation mentioning it.

I don't want to authenticate with ADC, because it's complicated, unaesthetic, requires files from what I have understood so far. I just want to have a simple API key that I can provide to the client and then call my chatbot. Simple.

Here is the current code :
```
const sessionClient = new dialogflow.SessionsClient({
projectId,
});

export async function getUserIntent(
sessionId: string,
query: string,
contexts: any,
languageCode: string = 'fr'
) {
const sessionPath = sessionClient.projectAgentSessionPath(
projectId,
sessionId
);

const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode,
},
},
queryParams: {},
};

if (contexts && contexts.length > 0) {
request.queryParams = {
contexts,
};
}

const responses = await sessionClient.detectIntent(request);
return responses[0];
}
```

But I have the following error :
```
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (C:\dev\repos\raskyer\la-plateforme\web\node_modules\google-auth-library\build\src\auth\googleauth.js:207:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at GoogleAuth.getClient (C:\dev\repos\raskyer\la-plateforme\web\node_modules\google-auth-library\build\src\auth\googleauth.js:624:17)
at GrpcClient._getCredentials (C:\dev\repos\raskyer\la-plateforme\web\node_modules\google-gax\build\src\grpc.js:145:24)
at GrpcClient.createStub (C:\dev\repos\raskyer\la-plateforme\web\node_modules\google-gax\build\src\grpc.js:308:23)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.