ошибка развертывания firebase в облачных сообщениях firebase - PullRequest
0 голосов
/ 26 марта 2020

Я интегрирую приложение чата. Когда я вхожу в систему, я добавляю токен fcm в базу данных Firebase, а когда в чате отправителя и получателя, я получаю уведомление о чате с обеих сторон. Поэтому я сделал ниже шаг

  1. install node.js
  2. Я использую версию узла (v13.11.0) и npm версию (6.13.7)
  3. , затем я использую npm install -g firebase-tools (firebase-tools@7.16.1 обновление 1 пакета за 18.481 с)
  4. вход в firebase (уже вошли как)
  5. создайте папку и добавьте путь, затем выполните команду firebase init cmd после функции select, затем добавьте мой проект, выберите язык, установите npm (инициализация Firebase завершена!)
  6. Я добавляю ниже код в указателе. js
    'use strict'
    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    exports.sendNotification = functions.database.ref('/Notifications/{receiver_id}/{notification_id}')
    .onWrite((data, context) =>
    {
        const receiver_user_id = context.params.receiver_user_id;
        const notification_id = context.params.notification_id;
        console.log('We have a notification to send to :' , receiver_user_id);
        if (!data.after.val()) 
        {
            console.log('A notification has been deleted :' , notification_id);
            return null;
        }
        const DeviceToken = admin.database().ref(`/Users/${receiver_user_id}/device_token`).once('value');
        return DeviceToken.then(result => 
        {
            const token_id = result.val();
            const payload = 
            {
                notification:
                {
                    title: "New Chat Request",
                    body: `you have a new Chat Request, Please Check.`,
                    icon: "default"
                }
            };
            return admin.messaging().sendToDevice(token_id, payload)
            .then(response => 
                {
                    console.log('This was a notification feature.');
                });
        });
    });
выполнить команду развертывания Firebase У меня ниже ошибка
=== Deploying to 'notification-ad12a8'...

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

**Error: An unexpected error has occurred.**

Я пробовал 3-4 раза, но не нашел решения. Пожалуйста, проверьте код, пожалуйста, помогите мне .. спасибо

...