Reputation: 177
Dialogflow V2 API relies on Google Auth, is it possible to use Dialogflow V2 API without install anything (SDK, composer or anything) into the server? I must to just use PHP\JS as usual, this is mandatory due the integration will be for a commercial plugin used by WordPress users, of course the users will never install anything to the server and anyway it's not possible to install anything on common web hostings. Thank you!
Upvotes: 2
Views: 758
Reputation: 6800
You don't need to install anything to use Dialogflow.
You just need to export Service Account Key (JSON) file, and set an environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. Then you can make call to dialogflow.
UPDATE :
Make sure you are using Dialogflow v2.
Go to general settings and click on your Service Account. This will redirect you to Google Cloud Platform project’s service account page.
Next step is to create a new key for the service account. Now create a service account and choose JSON as output key. Follow the instructions and a JSON file will be downloaded to your computer. This file will be used as GOOGLE_APPLICATION_CREDENTIALS
.
Now in code,
import os
import dialogflow
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/file.json"
project_id = "your_project_id"
session_id = "your_session_id"
language_code = "en"
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response_dialogflow = session_client.detect_intent(session=session, query_input=query_input)
Hope it helps.
Upvotes: 2