将 bitcoin-info-action 部署到 firebase 时无法获取函数 URL

Can not get the function URL when deploying bitcoin-info-action to firebase

我正在部署https://github.com/greenido/bitcoin-info-action with instructions from https://codelabs.developers.google.com/codelabs/your-first-action-on-google-with-webhook/#0

当我使用示例中提供的 Webhook URL 时,它工作正常。当我自己使用代码为 webhook 构建和部署时,它不会生成函数 URL.

步骤如下:

  1. 克隆 Git 回购 https://github.com/greenido/bitcoin-info-action
  2. 执行 firebase init 执行 firebase 部署(将所有模块安装为 需要)
  3. 我没有更改 index.js ,查看了 和其他人的答案。

我检查了左侧菜单中的 firebase 控制台和功能,但没有找到 URL,而是部署说明(与我使用的相同)

这是 firebase 部署的输出:

[google-tester-mn1:~/soverflow/bitcoin-info-action-master ] $ /Users/google-tester/.nvm/versions/node/v9.3.0/lib/node_modules/firebase-tools/bin/firebase deploy

=== Deploying to 'bitcoininfo-5cb78'...

i  deploying functions, hosting
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  hosting: preparing public directory for upload...
✔  hosting: 2 files uploaded successfully

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/bitcoininfo-5cb78/overview
Hosting URL: https://bitcoininfo-5cb78.firebaseapp.com

这里是 deploy --only 函数的输出:

Deploying to 'bitcoininfo-5cb78'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

 ✔  Deploy complete!

 Project Console: https://console.firebase.google.com/project/bitcoininfo-5cb78/overview

目录内容:

[google-tester-mn1:~/soverflow/bitcoin-info-action-master/functions ] $ ls -l ~/soverflow/bitcoin-info-action-master total 96 -rwxr-xr-x@ 1 google-tester google-tester 1642 Nov 16 17:04 CONTRIBUTING.md -rwxr-xr-x@ 1 google-tester google-tester 11325 Nov 16 17:04 LICENSE -rwxr-xr-x@ 1 google-tester google-tester 3255 Nov 16 17:04 README.md -rw-r--r--@ 1 google-tester google-tester 796 May 1 2017 agent.json -rw-r--r--@ 1 google-tester google-tester 3865 Nov 16 17:04 bitcoin-info-io17.zip -rw-r--r-- 1 google-tester google-tester 134 Dec 29 11:42 firebase.json drwxr-xr-x 6 google-tester google-tester 204 Dec 29 12:31 functions -rwxr-xr-x@ 1 google-tester google-tester 4411 Nov 16 17:04 index.js drwxr-xr-x@ 7 google-tester google-tester 238 Dec 29 11:39 intents -rwxr-xr-x@ 1 google-tester google-tester 647 Nov 16 17:04 package.json drwxr-xr-x 4 google-tester google-tester 136 Dec 29 11:42 public -rwxr-xr-x@ 1 google-tester google-tester 2476 Nov 16 17:04 webhook-example-bitcoin.php

Again:

[google-tester-mn1:~/soverflow/bitcoin-info-action-master/functions ]ls -l ~/soverflow/bitcoin-info-action-master/functions/ total 576 -rw-r--r--@ 1 google-tester google-tester 4411 Dec 29 12:23 index.js drwxr-xr-x 124 google-tester google-tester 4216 Dec 29 12:24 node_modules -rw-r--r-- 1 google-tester google-tester 281603 Dec 29 12:24 package-lock.json -rw-r--r-- 1 google-tester google-tester 460 Dec 29 12:24 package.json

package.json 的内容:

{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase serve --only functions", "shell": "firebase experimental:functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "dependencies": { "actions-on-google": "^1.7.0", "firebase-admin": "~5.4.2", "firebase-functions": "^0.7.1" }, "private": true }

我拥有所有节点模块,包括 actions-on-google。没有关于缺少模块的错误。

问题是代码是为 Google Cloud Functions (GCF) 编写的(正如 Ido 在他的评论中指出的那样),而您正尝试使用 Cloud Functions for Firebase(CFF 或 GCFF)部署它).虽然 CFF 是在 GCF 之上构建的,但在注册函数本身的方式上存在一些细微差别。

使用 GCF,您需要:

  1. 导出函数
  2. 将代码上传到 GCF(使用 gcloud 命令行工具或使用控制台)
  3. 如果您使用控制台,请添加函数

使用 GCFF 时,您需要:

  1. 在您的代码中需要 firebase-functions 库(通常带有 const functions = require('firebase-functions'); 之类的东西)
  2. 在您的代码中导出 functions.https.onRequest(...) 的结果
  3. 部署 firebase deploy

我已经提交了请求 Ido 来更改他的代码 (https://github.com/greenido/bitcoin-info-action/pull/4) or you can just pull it from master at https://github.com/afirstenberg/bitcoin-info-action.

如果您转到您的 firebase 控制台(使用您的网络浏览器),履行 URL 也在那里。