Попытка выучить и выполнить самые основные действия для Google Assistant (Уровень 2) в codelabs от Google.https://codelabs.developers.google.com/codelabs/actions-2/index.html#2
Запуск OSX 10.14.5 на MB Pro 2018. Работа в терминале и использование Atom для редактирования файлов.
Я прошел первый уровень и получаю всевозможные ошибки прав доступа и функцииошибки выполнения с npm и firebase.
Мне не удалось просто установить npm с помощью команды npm install.Пришлось дать себе разрешение на установку в нужную папку.Затем мне пришлось добавить зависимости самостоятельно, а также указать на правильный движок в моем пакете. Json
Наконец-то я оказался в месте, где я могу выполнить команду install npm, и она завершается без ошибок.Затем я пытаюсь развернуть firebase --project PROJECT_ID
Я получаю следующую ошибку
=== Deploying to 'actions-codelab-a9731'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (55.46 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 8 function dialogflowFirebaseFulfillment(us-central1)...
⚠ functions[dialogflowFirebaseFulfillment(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase-admin'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/apps.js:25:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Functions deploy had errors with the following functions:
dialogflowFirebaseFulfillment
To try redeploying those functions, run:
firebase deploy --only functions:dialogflowFirebaseFulfillment
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Richards-MacBook-Pro-2:functions richardr$
Мой файл pkg.json выглядит следующим образом
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"logs": "firebase functions:log"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0",
"firebase-functions": "^3.0.1"
},
"devDependencies": {
"firebase-admin": "^8.1.0",
"ajv": "^5.5.2",
"eslint": "^4.19.0",
"eslint-config-google": "^0.9.1",
"install-peers": "^1.0.3"
}
}
И это мойindex.js
// Copyright 2018, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('Your lucky number is ' + luckyNumber);
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Спасибо за помощь!