Context:
My app makes use of VoIP using TwiML, I store call records and additional data in Firebase. When a call is created, Twilio is a central point where the call gets created/cancelled. For this reason, when making a call I make use of Firebase to create a call entry in Firebase.
Looked for some documentation online for this issue, support or similar issues but came up short. The issue is quite simple:
Log output:
I see log output up to this message:
getting profile from
then get this error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/var/task/node_modules/google-auth-library/build/src/auth/googleauth.js:180:19) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async GoogleAuth.getClient (/var/task/node_modules/google-auth-library/build/src/auth/goo...
TwiML app code similar to Firebase Functions:
const AccessToken = require('twilio').jwt.AccessToken;
const VoiceGrant = AccessToken.VoiceGrant;
const VoiceResponse = require('twilio').twiml.VoiceResponse;
// Import the functions you need from the SDKs you need
const firebase = require("firebase-admin")
const firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
console.log("initializing firebase")
const app = firebase.initializeApp(firebaseConfig);
exports.handler = async function(context, event, callback) {
console.log("Running make-call")
const from = event.From;
let to = event.to;
//...
console.log("getting profile from")
// exception is thrown at this line below
var callerProfileSnap = await firebase.firestore(app).collection("profiles").doc(from).get();
// originally had this, but attempted loading the app manually as "credentials" couldn't be loaded made me think this might be an issue
// var callerProfileSnap = await firebase.firestore().collection("profiles").doc(from).get();
// ... continuation of code
var voiceResponse;
callback(null, voiceResponse);
}
Any idea what can cause this/why this occurs? Not finding much in the way of solutions online
The solution was a simple one, caused by an oversight.
Twilio automatically prepends "client:" to the event.From field. This I was attempt to find a document client:abcd1234... in firestore which didn't exists.
The error was however misleading, having nothing to do with incorrrect credentials but was infact a missing firestore document.
Possible solutions:
Check if event.From contains "client:", if so call .split(":")[1] to get the ID or latter portion of the From parameter.
payload object.e.g. adding custom parameters like:
customParams: {
"hello": "world",
"another": "entry"
}
will then be available in the payload like like this:
payload.hellopayload.another