Google 云函数错误 - res.setHeader 不是函数

Google Cloud Function Error - res.setHeader is not a function

我正在尝试 运行 来自 Cloud Functions Documentation 的第一个示例。 我创建了我的函数,并从文档中复制并粘贴了示例。

更正:我从这里获取示例代码: https://api.ai/docs/getting-started/basic-fulfillment-conversation

我收到的第一个错误是;

res.setHeader is not a function

然后我尝试用另一个函数设置header like;

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        
    }));
};

并按照它在测试控制台上的显示方式进行操作;

我是不是漏掉了什么?

这是我的错误,我必须在创建时选择 HTTP 触发器。 现在可以正常使用了。