- Notifications
You must be signed in to change notification settings - Fork194
Node.js client library for Actions on Google
License
actions-on-google/actions-on-google-nodejs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This client library makes it easy to create Actions for the Google Assistant andsupports Dialogflow, Actions SDK (v2), and Smart Home fulfillment.
- Client Library GitHub repo
- Client Library reference docs
- Actions on Google docs
- Actions on Google samples
Install the library with eithernpm install actions-on-google oryarn add actions-on-google if you use yarn.
To support features under Developer Preview, the library has a specialpreview branch which can be installed using the@preview tag.
This is installed with eithernpm install actions-on-google@preview oryarn add actions-on-google@preview.
Thepreview tag will be kept up to date with every new version of the library.
You can use the Developer Preview version to experience exciting new features that we’re still testing to make sure we have the best developer experience, and help us providing feedback on the API design and feature set.
The APIs offered in Developer Preview have not matured to General Availability yet, which means:
- You can’t publish Actions that use features in Developer Preview.
- The APIs arepotentially subject to backwards incompatible changes.
// Import the appropriate service and chosen wrappersconst{ dialogflow, Image,}=require('actions-on-google')// Create an app instanceconstapp=dialogflow()// Register handlers for Dialogflow intentsapp.intent('Default Welcome Intent',conv=>{conv.ask('Hi, how is it going?')conv.ask(`Here's a picture of a cat`)conv.ask(newImage({url:'https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/imgs/160204193356-01-cat-500.jpg',alt:'A cat',}))})// Intent in Dialogflow called `Goodbye`app.intent('Goodbye',conv=>{conv.close('See you later!')})app.intent('Default Fallback Intent',conv=>{conv.ask(`I didn't understand. Can you tell me something else?`)})
// Import the appropriate service and chosen wrappersconst{ actionssdk, Image,}=require('actions-on-google')// Create an app instanceconstapp=actionssdk()// Register handlers for Actions SDK intentsapp.intent('actions.intent.MAIN',conv=>{conv.ask('Hi, how is it going?')conv.ask(`Here's a picture of a cat`)conv.ask(newImage({url:'https://developers.google.com/web/fundamentals/accessibility/semantics-builtin/imgs/160204193356-01-cat-500.jpg',alt:'A cat',}))})app.intent('actions.intent.TEXT',(conv,input)=>{if(input==='bye'||input==='goodbye'){returnconv.close('See you later!')}conv.ask(`I didn't understand. Can you tell me something else?`)})
conv.ask/conv.closecan be called with any of theResponsetypes.- All
Helperclasses are of theResponsetype.
appis an instance of typeDialogflowApp.appaccepts options of typeDialogflowOptions.convis an instance of typeDialogflowConversation.
appis an instance of typeActionsSdkApp.appaccepts options of typeActionsSdkOptions.convis an instance of typeActionsSdkConversation.
// Import the appropriate serviceconst{ smarthome}=require('actions-on-google')// Create an app instanceconstapp=smarthome()// Register handlers for Smart Home intentsapp.onExecute((body,headers)=>{return{requestId:'ff36...',payload:{// ...},}})app.onQuery((body,headers)=>{return{requestId:'ff36...',payload:{// ...},}})app.onSync((body,headers)=>{return{requestId:'ff36...',payload:{// ...},}})
appis an instance of typeSmartHomeApp.appaccepts options of typeSmartHomeOptions.
Export or run for your appropriate framework:
constfunctions=require('firebase-functions')// ... app code hereexports.fulfillment=functions.https.onRequest(app)
constfunctions=require('firebase-functions')// ... app code here// name has to be `dialogflowFirebaseFulfillment`exports.dialogflowFirebaseFulfillment=functions.https.onRequest(app)
constexpress=require('express')constbodyParser=require('body-parser')// ... app code hereconstexpressApp=express().use(bodyParser.json())expressApp.post('/fulfillment',app)expressApp.listen(3000)
// ... app code hereexports.fulfillment=app
Take a look at the docs and samples linked at the top to get to know the platform and supported functionalities.
This library usesyarn to run commands. Install yarn using instructions fromhttps://yarnpkg.com/en/docs/install or with npm:npm i -g yarn.
Install the library dependencies withyarn. If you want to run any of the sample apps, follow the instructions in the sample README.
Public interfaces, classes, functions, objects, and properties are labeled with the JSDoc@public tag and exported at the top level. Everything else that is not labeled@public and exported at the top level is considered internal and may be changed.
This library supports the following Services:
- Dialogflow v1 and v2
- Actions SDKv2 only
- Smart Home
This library supports only Actions SDK fulfillment version 2.
To ensure that your fulfillment uses version 2, set the"fulfillmentApiVersion": 2 property in your action package.
- Questions? Go toStackOverflow,Assistant Developer Community on Reddit orSupport.
- For bugs, please report an issue on Github.
- Actions on GoogleDocumentation
- Actions on GoogleCodelabs.
- Webhook Boilerplate Template for Actions on Google.
Please read and follow the steps in theCONTRIBUTING.md.
SeeLICENSE.
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, theGoogle APIs Terms of Service.
About
Node.js client library for Actions on Google
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.