Name: assistant-sdk-nodejs
Owner: Google Samples
Description: null
Created: 2018-05-07 21:27:51.0
Updated: 2018-05-15 04:34:39.0
Pushed: 2018-05-07 21:39:21.0
Homepage: null
Size: 9
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
credentials.json
google-oauthlib-tool
][https://github.com/GoogleCloudPlatform/google-auth-library-python-oauthlib] in a [Python 3][https://www.python.org/downloads/] virtual environment:on3 -m venv env
bin/python -m pip install --upgrade pip setuptools
bin/pip install --upgrade google-auth-oauthlib[tool]
google-oauthlib-tool
][https://github.com/GoogleCloudPlatform/google-auth-library-python-oauthlib] to generate credentials:bin/google-oauthlib-tool --client-secrets credentials.json \
--credentials devicecredentials.json \
--scope https://www.googleapis.com/auth/assistant-sdk-prototype \
--save
cd google-assistant-grpc
npm install
node googleassistant.js
t GoogleAssistant = require('./googleassistant');
t deviceCredentials = require('./devicecredentials.json');
t CREDENTIALS = {
ient_id: deviceCredentials.client_id,
ient_secret: deviceCredentials.client_secret,
fresh_token: deviceCredentials.refresh_token,
pe: "authorized_user"
t assistant = new GoogleAssistant(CREDENTIALS);
The GoogleAssistant
class has several methods and helpers.
.assist(string)
- Sends a string request to the Assistant. Returns a promise with the text response or device action if applicable..setDeviceConfig(modelid, instanceid)
- Sets the device model and instance. This will need to be set with the model id you defined in the Actions Console to use device actions..startConversation([initialPrompt])
- Starts a conversation with “my test app”. Returns a promise with the text response..startConversationWith(appName, [initialPrompt])
- Starts a conversation with an Assistant app. Returns a promise with the text response..endConversation()
- Ends a conversation with an Assistant app. Returns a promise..setLocale(locale)
- Changes the Assistant locale, in the format en-US.stant.assist('what time is it')
hen(({ text }) => {
console.log(text); // Will log "It's 12:30"
;
You can chain together several requests and responses with Promises, as shown below.
stant.assist('what is the weather')
hen(({ text }) => {
console.log(text);
return assistant.assist('what about the weather tomorrow')
hen(({ text }) => {
console.log(text);
;
See LICENSE
.