I tried this with TypeScript on Firebase Functions:
import * as twilio from 'twilio';
function generateToken(iden,room){
const token = new twilio.AccessToken(
envconf.twilio.sid,
envconf.twilio.apikey,
envconf.twilio.apisecret,
)
token.identity = iden;
const grant = new twilio.AccessToken.VideoGrant()
token.addGrant(grant);
return token.toJwt();
}
but I get this error in logs:
TypeError: AccessToken is not a constructor
but this is like how they did it in the documentations . So maybe I should switch from TypeScript to Javascript?
I moved it to the Javascript, I get the same error. So this is not a TypeScript/Javascript compatibility issue.
I changed
const token = new twilio.AccessToken(
to
const token = new twilio.jwt.AccessToken(
and for some reason, it worked! I didn't post this update as an answer, because I don't understand why what they wrote in the example doesn't work and this works!
Try to import twilio as :
const { twilio} = require('twilio');
Or
import { twilio } from 'twilio'
这是文档中的错误,他们已将其修复。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.