lkaric / nestjs-twilio

Injectable Twilio client for Nestjs.
https://www.npmjs.com/package/nestjs-twilio
MIT License
42 stars 10 forks source link

How can I generate a client token using nestjs-twilio? #57

Closed alexis1111 closed 1 year ago

alexis1111 commented 1 year ago

i can't find a way to generate a token like this const AccessToken = require('twilio').jwt.AccessToken;, this appears on the twilio api docs but not here :/

lkaric commented 1 year ago

This is just a general wrapper around the Twilio SDK, I'm willing to try and help you with the issue, but I'll need more context.

alexis1111 commented 1 year ago

This is just a general wrapper around the Twilio SDK, I'm willing to try and help you with the issue, but I'll need more context.

Sure! i need to generate a token to grant access to the video feature on the client app, im using the following code

async generateToken(user: string): Promise<any> {
    const AccessToken = twilio.jwt.AccessToken;
    const VideoGrant = AccessToken.VideoGrant;

    const grant = new VideoGrant({
      room: 'test-room',
    });

    const token = new AccessToken(
      process.env.TWILIO_ACCOUNT_SID,
      process.env.TWILIO_API_KEY,
      process.env.TWILIO_API_SECRET,
      { identity: user },
    );

    token.addGrant(grant);

    return { 'twilio-token': token.toJwt() };
  }

im using twilio directly like this import * as twilio from 'twilio';, but it would be nice to just use this.twilioService.jwt.AccessToken

thank you so much for replying!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.