文档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 = ...
app
变量可以通过表达请求和响应对象来调用,因为它是一个函数: