在定制解决方案中,Twilio帐户如何与普通用户帐户关联?



我是Twilio的新手,我正在考虑构建一个用户可以拨打电话号码的应用程序。

从Twilio方面来看,我想我们需要为每个用户提供Twilio帐户(每个用户将拥有自己的Twilio电话号码,需要能够拨打电话)。

所以我猜我们需要在数据库中有常规用户帐户,并且对于每个常规用户,将Twilio认证令牌(以及其他Twilio凭据,如果需要)存储为用户字段。当用户需要呼叫时,我们只需使用相应的认证令牌。

用户本身,有Twilio帐户和号码,但他们不应该知道这些。他们只知道这个应用程序,他们登录并打电话。我猜管理员应该在Twilio控制台中为他们创建Twilio帐户?我同意由管理员来支付电话费,因为用户会根据管理员的请求来拨打电话。

这是Twilio应该如何工作,它应该如何连接到常规用户配置文件,当我们有完全定制的UI的情况下?

创建twilio主帐户。然后,每当用户在你的应用程序上创建一个帐户时,你就以编程方式为每个用户创建一个子帐户。然后,当您购买电话号码时,您通过主帐户凭据购买电话号码,并将电话号码传递给子帐户。很确定这就是它的工作原理。检查我创建的这个护照登录


passport.use(
new GoogleStrategy({
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: '/auth/google/callback',
proxy: true
},
async (accessToken, refreshToken, profile, done) => {
const existingUser = await User.findOne({googleId: profile.id})
if (existingUser) {
done(null, existingUser)
} else {
const client = require('twilio')(accountSid, authToken); // get our master account credentials
const actServiceSid = await client.api.accounts // create sub account, this variable holds the return data
.create({friendlyName: profile.displayName }) // name it with profiles displayName ex. Christian Moosey
.then(account => { return {sid: account.sid, authToken: account.authToken}}) // return our new sub account auth credentials
const subClient = require('twilio')(actServiceSid.sid, actServiceSid.authToken) // these are our sub account credentials
const msgServiceSid = await subClient.messaging.services // subaccount credentails / whatever service we need
.create({
friendlyName: profile.displayName,
inboundRequestUrl: "http://a30-b81e-5e93-f40b-34f.ngrok.io/webhook-incoming-message"
}) // create messaging service name
.then(service => { return console.log(service), {sid: service.sid}}) // return the sid in an object
const convoServiceSid = await subClient.conversations.services // subaccount credentials / create conversations service
.create({friendlyName: profile.displayName}) // make it look like christian moreno
.then(service => { return {sid: service.sid}}); // return and object with a sid key to convoServiceSid variable
const keys = await subClient.newKeys.create({friendlyName: profile.displayName})
.then(new_key => { return { keySid: new_key.sid, keySec: new_key.secret}})
const twimlApp = await subClient.applications
.create({
voiceMethod: 'POST',
voiceUrl: 'https://-00-96fb.ngrok.io/voice',
friendlyName: 'Phone Me'
})
.then(application => { return {twimlApp: application.sid}});
const customer = await stripe.customers.create({
email: profile.emails[0].value,
}).then(customer => { return {customerId: customer.id}});
const user = await new User({ 
googleId: profile.id,
displayName: profile.displayName,
image: profile.photos[0].value,
email: profile.emails[0].value,
firstName: profile.name.givenName,
lastName: profile.name.familyName,
msgServiceSid: msgServiceSid.sid,
convoServiceSid: convoServiceSid.sid,
subActServiceSid: actServiceSid.sid,
subActAuthToken: actServiceSid.authToken,
stripeCustomerId: customer.customerId,
twilKeySid: keys.keySid,
twilKeySec: keys.keySec,
twimlAppSid: twimlApp.twimlApp
}).save()
done(null, user);

}
}
)
)

最新更新