【发布时间】:2017-12-23 22:48:06
【问题描述】:
我正在尝试从Cloud Functions Documentation 运行第一个示例。 我创建了我的函数,并从文档中复制并粘贴了示例。
更正:我从这里获取了示例代码: https://api.ai/docs/getting-started/basic-fulfillment-conversation
我收到的第一个错误是;
res.setHeader 不是函数
然后我尝试使用另一个函数来设置标题:
res.writeHead(200, { 'Content-Type': 'application/json' });
但这也给了我同样的错误。 这是我的以下代码;
/**
* Cloud Function.
*
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloHttp = function helloHttp(req, res) {
response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working
// res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
res.writeHead(200, { 'Content-Type': 'application/json' });
//"speech" is the spoken version of the response, "displayText" is the visual version
res.send(JSON.stringify({
"speech": response,
"displayText": response
}));
};
并遵循它在测试控制台上的显示方式;
我错过了什么吗?
【问题讨论】:
标签: node.js google-cloud-functions