Node/Twilio多重配置变量在需要功能
我想知道,当使用Twilio作为节点时,是否有人设法找到了一种使用多个帐户SIDS和auth令牌的方法。该文档非常简单,我可以将Twilio与自己的凭据一起使用。
但是,在使用Twilio上的子用户时,我希望能够在购买电话号码的过程中使用其凭据。我目前有一个app.post路由,该路由首先获取特定用户的SID和auth标记。
let twilioSid = process.env.REACT_APP_TWILIO_ACCOUNT_SID;
let twilioAuthToken = process.env.REACT_APP_TWILIO_AUTH_TOKEN;
let twilioClient = require('twilio')(twilioSid, twilioAuthToken);
在进行该号码的实际“购买”之前,我在调用函数之前检索Subuser SID和Auth token并更新我的变量,例如:
const user = await admin.firestore().collection("users").doc(userId).get()
twilioSid = user.data().sid;
twilioAuthToken = user.data().authToken;
const purchase = await twilioClient.incomingPhoneNumbers.create({phoneNumber: number})
购买起来,但仅适用于我的主要(父(父)帐户,都存储在.env
。似乎最高变量从未在IncoMiingphoneNumbers之前实际进行更新。谁能将我指向我如何使用子用户凭据来运行此功能的正确方向?
I was wondering if any other people have managed to find a way to use multiple account sids and auth tokens when using Twilio for Node. The documentation is pretty straight forward, and I am able to use Twilio with my own credentials.
However, while using subusers on Twilio, I want to be able to use their credentials in the process of purchasing a phone number. I currently have a app.post route which first fetches the sid and auth token of the specific user.
let twilioSid = process.env.REACT_APP_TWILIO_ACCOUNT_SID;
let twilioAuthToken = process.env.REACT_APP_TWILIO_AUTH_TOKEN;
let twilioClient = require('twilio')(twilioSid, twilioAuthToken);
Before doing the actual "purchase" of that number, I retrieve the subuser sid and auth token and update my variable before I call the function, like so:
const user = await admin.firestore().collection("users").doc(userId).get()
twilioSid = user.data().sid;
twilioAuthToken = user.data().authToken;
const purchase = await twilioClient.incomingPhoneNumbers.create({phoneNumber: number})
The purchase works, but only for my main (parent) account with the credentials stored in .env
. It seems that the top variables never actually gets updated before the incomiingPhoneNumbers.create gets called. Can anyone point me in the right direction on how I would be able to use the subuser credentials to run this function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新变量仅在这里无法完成工作,因为您已经初始化了客户端。当您重新启动客户端时(或者只是启动另一个客户)时,它应该起作用:
或
Updating the variables only won't do the job here because you already initialized the client. It should work when you reinitialize the client (or just init another client):
or