I have implemented a simple chat using Twilio conversations API. I'm following the doc for web push notifications (https://www.twilio.com/docs/conversations/javascript/push-notifications-web) and it's not clear to me what "FCM SECRET" I need to include in my Twilio Credential. I have tried with my firebase app key pair (public and private) and also with firebase web API key, but in the Twilio logs I allways get a GCM/FCM unauthorized error: GCM/FCM API key is revoked or invalid error.
Update:
My app code:
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.2/firebase-app.js";
import { getMessaging, getToken, onMessage } from "https://www.gstatic.com/firebasejs/9.8.2/firebase-messaging.js";
const firebaseConfig = {
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "..."
};
const firebase = initializeApp(firebaseConfig);
const messaging = getMessaging(firebase);
const serviceWorkerRegistration = await navigator
.serviceWorker
.register('/js/firebase/firebase-messaging-sw.js');
if (firebase && messaging) {
// getting FCM token
getToken(messaging, {
vapidKey: '...',
serviceWorkerRegistration: serviceWorkerRegistration,
}).then(async (fcmToken) => {
console.log('token', fcmToken)
const conversationsClient = await getConversationsClient();
conversationsClient.setPushRegistrationId('fcm', fcmToken);
onMessage(messaging, payload => {
console.log('Message received. ', payload);
conversationsClient.handlePushNotification(payload);
});
}).catch((err) => {
console.log('Error getting token', err);
});
} else {
// no Firebase library imported or Firebase library wasn't correctly initialized
}
The fcmToken is generated and successfuly registered in Twilio.
The Binding is created In Twilio with my credential referenced:
I believe the FCM Secret should be the apiKey that you get when you register the web application and get the details like this:
You also need to ensure you are using that config when you initialize the Firebase SDK in your application.
If you are using that config, then perhaps you can share the code that you are using in your app to initialize Firebase and request an fcmToken from the user.