I need to send push notification with expo and firebase clouud function because of I m using firebase database.
it will triggered and send push when there is any update on firebase database. is there any solution for this issue???
firebase cloud function is not support (async functions) so ı could not use the “await …” type for exponent-server-sdk. how can I handle it?
I’m interested in a solution to this as well. It seems like I should be able to just write a cloud function that uses the ExpoClient described in their node documentation however when I try to do that, it doesn’t seem to work. Perhaps it’s because I’m not installing the expo-client-sdk correctly? I’m still new to firebase so if that’s the case, I’ll need another solution to handle push notifications.
Are you on a paid plan for Firebase? The free plan only allows for outbound network requests to Google-owned services. In order to use the expo node server, you’ll have to be on a paid plan.
So it looks like my issue was I was importing is incorrectly. I was following the import syntax for the docs but that didn’t work on firebase, I had to do something like import * as Expo from 'expo-server-sdk'
I used your tutorial and everything works. but i keep getting this error in the cloud function. its firing off and im getting the data etc. but its not doing the route correctly.
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { Expo, ExpoPushMessage } from 'expo-server-sdk';
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
// export const helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
admin.initializeApp()
//let expo = new Expo();
export const prueba = functions.firestore.document('prueba/TY6SCYQwSEk1M7sPzWK4').onUpdate(()=>{
//const allTokens = [];
const messages: ExpoPushMessage[] = [];
const exp = new Expo()
for (const pushToken of ["ExponentPushToken[Ixxxxxxxxxxxxxxxxxxxxxxn]"]) {
// Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
// Check that all your push tokens appear to be valid Expo push tokens
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}else{
console.log("funciono el atoken");
}
// Construct a message (see https://docs.expo.io/versions/latest/guides/push-notifications)
messages.push({
to: pushToken,
sound: 'default',
body: 'Dalvin Notificacion',
data: { withSome: 'data' },
})
}
const chunks = exp.chunkPushNotifications(messages);
// Send the chunks to the Expo push notification service. There are
// different strategies you could use. A simple one is to send one chunk at a
// time, which nicely spreads the load out over time:
for (const chunk of chunks) {
try {
const ticketChunk = exp.sendPushNotificationsAsync(chunk);
console.log(ticketChunk);
// NOTE: If a ticket contains an error code in ticket.details.error, you
// must handle it appropriately. The error codes are listed in the Expo
// documentation:
// https://docs.expo.io/versions/latest/guides/push-notifications#response-format
} catch (error) {
console.error(error);
}
}
});
I used firebase functions and expo to push notifications
But when I sign up by phone to firebase, It has error like: auth/invalid-app-credential
Does anyone occor this problem?