Created
January 29, 2024 01:01
-
-
Save abundis29/a0d2fc3d4210938f561374f962239afd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AccessToken = require('twilio').jwt.AccessToken; | |
const VoiceGrant = AccessToken.VoiceGrant; | |
// Used when generating any kind of tokens | |
// To set up environmental variables, see http://twil.io/secure | |
// Used specifically for creating Voice tokens | |
const outgoingApplicationSid = 'APd03584f63d77249726a31e44e315398'; | |
const identity = 'user'; | |
// Create a "grant" which enables a client to use Voice as a given user | |
const voiceGrant = new VoiceGrant({ | |
outgoingApplicationSid: outgoingApplicationSid, | |
incomingAllow: true, // Optional: add to allow incoming calls | |
}); | |
console.log(voiceGrant) | |
// Create an access token which we will sign and return to the client, | |
// containing the grant we just created | |
const token = new AccessToken( | |
twilioAccountSid, | |
twilioApiKey, | |
twilioApiSecret, | |
{identity: identity} | |
); | |
token.addGrant(voiceGrant); | |
// Serialize the token to a JWT string | |
console.log(token.toJwt()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment