根据Express请求创建Google行动对象

问题描述 投票:0回答:1

文档here显示了用于为Express创建Actions SDK对象的此代码示例:

const express = require('express');
const bodyParser = require('body-parser');

const expressApp = express().use(bodyParser.json());
expressApp.post('/fulfillment', app);
expressApp.listen(3000);

但是我需要做这样的事情:

const express = require('express');
const bodyParser = require('body-parser');

function func (req, res) {
    let headers = req.headers;
    let body = req.body;

    console.log(headers);
    console.log(body);

    const app = actionssdk({
        // init: () => body
        // init: () => req
    });

    app.intent('actions.intent.MAIN', (conv) => {
        conv.ask("Welcome to the app");
    })
    return app;
}

const expressApp = express().use(bodyParser.json());
expressApp.post('/fulfillment', func);
expressApp.listen(3000);

这显然不是正确的语法,它不会返回对Google Action的任何响应。

我想要执行类似操作的原因是使用动态actionssdk初始化clientId对象。我可以从projectId对象中存在的授权标头中提取req.headers。我可以从projectId中动态获取clientId并通过传递actionssdk]来初始化clientId

正确的语法是什么?

这里的文档显示了用于为Express创建Actions SDK对象的以下代码示例:const express = require('express'); const bodyParser = require('body-parser'); const expressApp = ...

actions-on-google
1个回答
0
投票

app变量可以通过表达请求和响应对象来调用,因为它是一个函数:

© www.soinside.com 2019 - 2024. All rights reserved.