Can I deploy fulfillment in my own server with Actions SDK?

南笙酒味 提交于 2019-12-03 21:51:29

Here is one working example with nodeJs library

'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.")
})

above example will return "Hello World"

You also need to keep in mind that api.ai & actions-on-google only accept https fulfillment. Without SSL you won't be able to connect to your webhook.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!