Я пытаюсь добавить функцию push-уведомлений в моем проекте Android с помощью nodejs с помощью firebase. Я установил инструменты firebase и подключился к своему проекту.
Вот файл index.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(event =>
{
const receiver_id = event.params.receiver_id;
const notification_id = event.params.notification_id;
console.log('We have new notification to send to : ', receiver_id);
if(!event.data.val())
{
return console.log('A notification has been deleted from the database :', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`).once('value');
return deviceToken.then(response =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "Friend Request",
body: "You have received a new Friend Request",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response =>
{
console.log('This was the notification feature');
});
});
});
Когда я пытаюсь развернуть файл, я получаю эту ошибку:
33: 11 предупреждение Избегайте вложенных обещаний обещание / отсутствие вложений
33:66 ошибка
Каждый then () должен возвращать значение или выдавать обещание / всегда возвращать
problems 2 проблемы (1 ошибка, 1 предупреждение)
нпм ERR! код ELIFECYCLE
нпм ERR! errno 1
нпм ERR! functions @ lint: eslint .
нпм ERR! Статус выхода 1
npm ERR!
нпм ERR! Ошибка в скрипте functions @ lint.
npm ERR! Это, вероятно, не проблема с npm. Скорее всего, выше выводится логирование.
Ошибка: ошибка функции перед развертыванием: команда завершена с ненулевым кодом выхода1