“我的Google Actions”项目将Google Cloud Function用作Webhook。在Google云功能中,我可以使用conv.ask(...)
创建对话响应。
但是,我想做的是:构建一个通用的对话内容框架,该框架驻留在另一台服务器(也是Google云功能)上,我想在其中撰写响应并将其发送回webhook函数。
这两个服务器中的相关代码如下:
// in the webhook function
app.intent('actions.intent.MAIN', (conv, input) => {
// here I would like to call the second google function by
// passing, say, the input and receiving a response that can
// be passed on to the conv
// something like
// assume request-promise is being used
//
var options = {
method: 'POST',
uri: '..',
body: {...},
json: true
};
rp(options)
.then(resp => {
conv.ask(resp) // this is what I would like to do
});
});
在第二台Google Functions服务器中,我使用express作为中间件。在此建立一些逻辑化的模板化响应
const ..
const {
SimpleResponse,
BasicCard,
...
} = require('actions-on-google');
...
const express = require('express');
var app = express();
...
app.post('/main', function(req, res, next) {
// here I would like to compose the response
// and send it to the earlier function
var convresp = new SimpleResponse({...});
..
res.send(convresp);
// this seems to be only sending the json
// and causes the receiving response to give an error
// when applying to conv.ask in the above code
});
问题是:应该如何从第二个函数发送响应,以便可以将其“粘贴”到第一个函数中的conv.ask
功能?谢谢