Im am trying to read data off my database and then send a message through Twilio. What I am expecting this function to do is to check the database every minute. it will check all the documents inside the players collection. If the sessions field in one of these documents is equal to 0, then it creates a message and sends it to the phone number in that same document.
here is my current code:
const account = '***********************************';
const auth = '********************************';
const client = require('twilio')(account,auth);
const firebaseFunc = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const database = admin.firestore()
exports.paymentChecker = firebaseFunc.pubsub.schedule('* * * * *').onRun((context) => {
database.collection('Players').get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
if(doc.data().sessions, '==', 0){
client.messages.create({
to: doc.data().phone,
from: '+***********',
body: 'Hi' + doc.data().First + ', you have to renew your registration',
})
}
})
}).catch()
})
however, this code is not deploying to firebase as it is yielding a number of errors.
19:5 error Expected catch() or return promise/catch-or-return
20:11 error Each then() should return a value or throw promise/always-return
22:16 error Unexpected constant condition no-constant-condition
how to resolve this? thanks