Node.js-ClientlibraryforActionsonGoogleusingNode.js

  • Y8_336324
    了解作者
  • 185.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-19 17:15
    上传日期
Client library for Actions on Google using Node.js
Node.js-ClientlibraryforActionsonGoogleusingNode.js.zip
内容介绍
# Actions on Google Client Library This client library makes it easy to create Actions for the Google Assistant and supports Dialogflow, Actions SDK, and Smart Home fulfillment. * [Client Library GitHub repo](https://github.com/actions-on-google/actions-on-google-nodejs) * [Client Library reference docs](https://actions-on-google.github.io/actions-on-google-nodejs/) * [Actions on Google docs](https://developers.google.com/actions/) * [Actions on Google samples](https://developers.google.com/actions/samples/) [![NPM Version](https://img.shields.io/npm/v/actions-on-google.svg)](https://www.npmjs.org/package/actions-on-google) [![Build Status](https://travis-ci.org/actions-on-google/actions-on-google-nodejs.svg?branch=master)](https://travis-ci.org/actions-on-google/actions-on-google-nodejs) ## Setup Instructions Install the library with either `npm install actions-on-google` or `yarn add actions-on-google` if you use yarn. ### Developer Preview To support features under Developer Preview, the library has a special [`preview`](https://github.com/actions-on-google/actions-on-google-nodejs/tree/preview) branch which can be installed using the `@preview` tag. This is installed with either `npm install actions-on-google@preview` or `yarn add actions-on-google@preview`. The `preview` 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 are **potentially subject to backwards incompatible changes**. ### Conversational Services #### Dialogflow ```javascript // Import the appropriate service and chosen wrappers const { dialogflow, Image, } = require('actions-on-google') // Create an app instance const app = dialogflow() // Register handlers for Dialogflow intents app.intent('Default Welcome Intent', conv => { conv.ask('Hi, how is it going?') conv.ask(`Here's a picture of a cat`) conv.ask(new Image({ 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?`) }) ``` #### Actions SDK ```javascript // Import the appropriate service and chosen wrappers const { actionssdk, Image, } = require('actions-on-google') // Create an app instance const app = actionssdk() // Register handlers for Actions SDK intents app.intent('actions.intent.MAIN', conv => { conv.ask('Hi, how is it going?') conv.ask(`Here's a picture of a cat`) conv.ask(new Image({ 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') { return conv.close('See you later!') } conv.ask(`I didn't understand. Can you tell me something else?`) }) ``` #### Notes about the code snippet * [`conv.ask`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.conversation-1.html#ask)/[`conv.close`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.conversation-1.html#close) can be called with any of the [`Response`](https://actions-on-google.github.io/actions-on-google-nodejs/modules/conversation.html#response) types. * All [`Helper`](https://actions-on-google.github.io/actions-on-google-nodejs/modules/conversation_helper.html) classes are of the `Response` type. ##### Dialogflow * `app` is an instance of type [`DialogflowApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/dialogflow.dialogflowapp.html#catch). * `app` accepts options of type [`DialogflowOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/dialogflow.dialogflowoptions.html#clientid). * `conv` is an instance of type [`DialogflowConversation`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html). ##### Actions SDK * `app` is an instance of type [`ActionsSdkApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/actionssdk.actionssdkapp.html#catch). * `app` accepts options of type [`ActionsSdkOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/actionssdk.actionssdkoptions.html#clientid). * `conv` is an instance of type [`ActionsSdkConversation`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/actionssdk.actionssdkconversation.html). ### Smart Home ```javascript // Import the appropriate service const { smarthome } = require('actions-on-google') // Create an app instance const app = smarthome() // Register handlers for Smart Home intents app.onExecute((body, headers) => { return { requestId: 'ff36...', payload: { // ... }, } }) app.onQuery((body, headers) => { return { requestId: 'ff36...', payload: { // ... }, } }) app.onSync((body, headers) => { return { requestId: 'ff36...', payload: { // ... }, } }) ``` #### Notes about the code snippet * `app` is an instance of type [`SmartHomeApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/smarthome.smarthomeapp.html#onexecute). * `app` accepts options of type [`SmartHomeOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/smarthome.smarthomeoptions.html#debug). ### Frameworks Export or run for your appropriate framework: #### Firebase Functions ``` javascript const functions = require('firebase-functions') // ... app code here exports.fulfillment = functions.https.onRequest(app) ``` #### Dialogflow Inline Editor ```javascript const functions = require('firebase-functions') // ... app code here // name has to be `dialogflowFirebaseFulfillment` exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app) ``` #### Self Hosted Express Server ```javascript const express = require('express') const bodyParser = require('body-parser') // ... app code here const expressApp = express().use(bodyParser.json()) expressApp.post('/fulfillment', app) expressApp.listen(3000) ``` #### AWS Lambda API Gateway ```javascript // ... app code here exports.fulfillment = app ``` ### Next Steps Take a look at the docs and samples linked at the top to get to know the platform and supported functionalities. ## Library Development Instructions This library uses `yarn` to run commands. Install yarn using instructions from https://yarnpkg.com/en/docs/install or with npm: `npm i -g yarn`. Install the library dependencies with `yarn`. If you want to run any of the sample apps, follow the instructions in the sample README. ## Functionality 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](https://dialogflow.com/docs/fulfillment) v1 and v2 * [Actions SDK](https://developers.google.com/actions/sdk/fulfillment) **v2 only** * [Smart Home](https://developers.google.com/actions/smarthome/create-app#provide-fulfillment) ### Actions SDK This library supports only Actions SDK fulfillment version 2. To ensure that your fulfillment uses version 2, set the [`"fulfillmentApiVersion": 2`](https://github.com/actions-on-google/actionssdk-eli
评论
    相关推荐
    • 用于Oauth2的简单Node.js客户端库-Node.js开发
      用于OAuth2的简单OAuth2 Node.js客户端库。 OAuth2允许用户通过第三方应用程序授予对受限资源的访问权限。 目录简单的OAuth2目录要求简单的OAuth2 OAuth2的Node.js客户端库。 OAuth2允许用户通过第三方应用程序授予...
    • Node.js-互联网的标准库
      互联网的标准库,The Standard Library of the Internet
    • node-ffi:Node.js外部函数接口
      node-ffi是一个Node.js插件,用于使用纯JavaScript加载和调用动态库。 它可以用于创建与本机库的绑定,而无需编写任何C ++代码。 由于它可以处理跨JavaScript和C的类型转换,因此还简化了C代码对node.js的扩充,这...
    • statsd-node-client-test:node.js statsd 客户端的测试套件
      我编写这个项目是为了测试多个 node.js 客户端对的性能。 我想找出 statsd 的可用 node.js 客户端之间的性能差异,所以我制作了这个 CLI 工具,它可以轻松地为每个测试切换选项。 它基本上根据来自 CLI 的输入执行...
    • Node.js-blelibrary和周边ble连接sample
      ble library 和周边 ble 连接 sample
    • chintz-node:Node.js 的 Chintz 客户端
      Node.js 的客户端 用法 这假设您有一个前端元素的库(mustache 模板、css、js 等,每个组件都有一个依赖项清单)。 初始化: var Chintz = require ( "chintz-node" ) ; var chintz = new Chintz ( "/absolute/...
    • Node.js-Libra的轻量级JavaScript
      Libra的轻量级JavaScript
    • Node.js-Library:Node.js实战源代码-js
      Node.js-Library:Node.js实战源代码
    • nodam:Node.js 异步 Monad
      NodAM 代表 Node.js 异步 Monad。 NodAM 通过异步调用为控制流提供简洁、直观的功能。 您可以序列化和并行化您的 IO 调用、组合序列和创建修改后的序列,而不会对原始序列产生任何影响。 如果您不知道 monad 是什么...
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档