【问题标题】:Can I deploy fulfillment in my own server with Actions SDK?我可以使用 Actions SDK 在我自己的服务器中部署履行吗?
【发布时间】:2017-08-22 10:32:10
【问题描述】:

我是初学者,我无法理解如何使用 Node.js 客户端库(Actions SDK)构建实现。开发文档使用 firebase 的 Actions SDK,但我不想通过 firebase 部署实现。

所以我不知道如何使用 Actions SDK 在我自己的服务器中部署实现。请告诉我该怎么做。谢谢!

【问题讨论】:

    标签: actions-on-google


    【解决方案1】:

    这是一个使用 nodeJs 库的工作示例

    'use strict';
    
    var express = require('express');
    var bodyParser = require('body-parser');
    var exps = express();
    
    const ApiAiApp = require('actions-on-google').ApiAiApp;
    
    exps.use(bodyParser.json());
    
    // API.AI actions
    const WELCOME_ACTION = 'input.welcome';
    
    exps.post('/hook', function(request, response) {
      const app = new ApiAiApp({request, response});
      function greetUser (app) {
        app.tell("Hello World!");
      }
    
      let actionMap = new Map();
      actionMap.set(WELCOME_ACTION, greetUser);
    
      app.handleRequest(actionMap);
    });
    
    exps.listen((process.env.PORT || 7001), function() {
        console.log("App up and running, listening.")
    })
    

    上面的例子将返回“Hello World”

    您还需要记住,api.ai 和 actions-on-google 只接受 https 实现。如果没有 SSL,您将无法连接到您的 webhook。

    【讨论】:

    • 谢谢!虽然我想创建一个智能家居应用程序(API.AI 不支持智能家居应用程序),但你的例子对我很有帮助。如果你有一些关于 ActionsSdkApp 的例子,它会更有帮助。再次感谢。
    • 我觉得这个链接可以帮到你actions-on-google-smartHome
    猜你喜欢
    • 1970-01-01
    • 2020-02-20
    • 2013-07-10
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 2015-06-09
    相关资源
    最近更新 更多