• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

actions-on-google/actions-on-google-nodejs: Node.js client library for Actions o ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

actions-on-google/actions-on-google-nodejs

开源软件地址(OpenSource Url):

https://github.com/actions-on-google/actions-on-google-nodejs

开源编程语言(OpenSource Language):

TypeScript 99.0%

开源软件介绍(OpenSource Introduction):

Actions on Google Client Library

This client library makes it easy to create Actions for the Google Assistant and supports Dialogflow, Actions SDK (v2), and Smart Home fulfillment.

⚠️ We now recommend using Actions Builder or the Actions SDK to develop, test, and deploy Conversational Actions. For Conversational Actions built using Actions Builder see the @assistant/conversation library.

NPM Version Build Status

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 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

// 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

// 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

Dialogflow
Actions SDK

Smart Home

// 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

Frameworks

Export or run for your appropriate framework:

Firebase Functions

const functions = require('firebase-functions')

// ... app code here

exports.fulfillment = functions.https.onRequest(app)

Dialogflow Inline Editor

const functions = require('firebase-functions')

// ... app code here

// name has to be `dialogflowFirebaseFulfillment`
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)

Self Hosted Express Server

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

// ... 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:

Actions SDK

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.

References & Issues

Make Contributions

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap