[英]TwiML app and Firebase throwing Unhandled promise rejection: Error: Could not load the default credentials
Context:语境:
My app makes use of VoIP using TwiML, I store call records and additional data in Firebase.我的应用通过 TwiML 使用 VoIP,我将通话记录和其他数据存储在 Firebase 中。 When a call is created, Twilio is a central point where the call gets created/cancelled.创建呼叫时,Twilio 是创建/取消呼叫的中心点。 For this reason, when making a call I make use of Firebase to create a call entry in Firebase.因此,在拨打电话时,我会使用 Firebase 在 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. UnhandledPromiseRejectionWarning:未处理的承诺拒绝:错误:无法加载默认凭据。 Browse to https://cloud.google.com/docs/authentication/getting-started for more information.浏览到https://cloud.google.com/docs/authentication/getting-started了解更多信息。 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...在 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 : TwiML 应用代码类似于 Firebase 函数:
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. Twilio 会自动将“client:”添加到event.From
字段。 This I was attempt to find a document client:abcd1234...
in firestore which didn't exists.我试图在不存在的 firestore 中找到一个文档client:abcd1234...
The error was however misleading, having nothing to do with incorrrect credentials but was infact a missing firestore document.然而,该错误具有误导性,与不正确的凭据无关,但实际上是缺少 firestore 文档。
Possible solutions:可能的解决方案:
Check if event.From
contains "client:", if so call .split(":")[1]
to get the ID or latter portion of the From
parameter.检查event.From
包含“client:”,如果是,则调用.split(":")[1]
以获取 ID 或From
参数的后面部分。
payload
object.使用从客户端发送的Twilio 自定义参数,这些参数将包含在payload
对象中。eg adding custom parameters like:例如添加自定义参数,如:
customParams: {
"hello": "world",
"another": "entry"
}
will then be available in the payload like like this:然后将在有效载荷中可用,如下所示:
payload.hello
payload.another
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.