-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with Typescript #374
Comments
The same case with
error Twilio.TwimlResponse is not a constructor |
In the newest version of the library the types come bundled so you don't need This is a bit confusing because the docs want you to use the |
Hey folks, Yes we silently released TS bindings with the latest release and definitely require feedback with this :) @Crazometer your comment is correct. I made that decision because of the way that the Twilio lib is written I had to decide between import twilio = require('twilio');
const client = twilio(); The first two examples are both from the old library. Since version 3.X TwiML is nested under import twilio = require('twilio');
const myTwiml = new twilio.twiml.VoiceResponse();
myTwiml.say({ voice: 'alice' }, 'Ahoy');
console.log(myTwiml.toString()); Note There is a known issue where right now you have to pass options to the respective TwiML methods. I hope it gets fixed soon. The code snippet above is also depending on a PR being merged that fixes a few of these issues. For the AccessTokens, they are now under // create AccessToken
const accessToken = new twilio.jwt.AccessToken(
process.env.TWILIO_ACCOUNT_SID!,
process.env.TWILIO_API_KEY!,
process.env.TWILIO_API_SECRET!,
{
ttl: 360,
}
);
// create Grant
const grant = new twilio.jwt.AccessToken.VideoGrant();
grant.toPayload();
const AccessToken = twilio.jwt.AccessToken;
const voiceGrant = new AccessToken.VoiceGrant({
incomingAllow: true,
outgoingApplicationSid: 'someSid',
});
voiceGrant.toPayload();
accessToken.addGrant(voiceGrant);
accessToken.addGrant(grant);
const token = accessToken.toJwt();
console.log(token); I hope this helps and your feedback is definitely wanted and helpful :) |
Oh, that's pretty cool thanks. I will remove @types and check it again. Thanks for quick response. Closing it. |
@dkundel - is there a way to define the type of a response object without instantiating it? e.g. let myTwiml: twilio.twiml.VoiceResponse;
myTwiml = new twilio.twiml.VoiceResponse(); The error message on the |
If you are using VS Code you should be able to use the AutoFix option to import the actual import * as VoiceResponse from './lib/twiml/VoiceResponse'; Your code doesn't work because of some odd internals that I had to oddly fix with TypeScript. Cheers, |
@dkundel - Thank you for your response. Maybe I'm confused but why would there be a |
Sorry my bad 😄 I was in that project. It would be Cheers, |
I have been following this documentation(https://github.com/TwilioDevEd/api-snippets/blob/master/rest/access-tokens/video-example/video-example.3.x.js) to generate a auth token.
Using
"twilio": "^3.19.1"
with"@types/twilio": "0.0.9",
seems like theVideoGrant
is unavailable and the Typescript andAccessToken.toJwt()
requires a String parameter which is not necessary.I ended up doing the following, but it would be nice to fix these.
Version: ^3.19.1
Code Snippet
Thanks
The text was updated successfully, but these errors were encountered: