Skip to content
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

Fix TypeScript related issues #377

Merged
merged 5 commits into from
Aug 30, 2018
Merged

Fix TypeScript related issues #377

merged 5 commits into from
Aug 30, 2018

Conversation

dkundel
Copy link
Member

@dkundel dkundel commented Aug 29, 2018

This PR fixes different TypeScript related binding issues found in #374, #376 and by @nash-md. Specifically this fixes:

  • Exporting TwiML constructors correctly as twilio.twiml.VoiceResponse etc.
  • Making all options in AccessTokenOptions optional to not force the user to provide all if one is present
  • Setting the algorithm argument in toJwt for AccessTokens to optional since a default value is present
  • Add allowIncoming as new option for VoiceGrantOptions
  • Marking the RequestValidatorOptions values as optional
Script used to verify changes
import twilio = require('twilio');

// creating a client
const client = twilio(
  process.env.TWILIO_ACCOUNT_SID,
  process.env.TWILIO_AUTH_TOKEN
);

// create TwiML
const myTwiml = new twilio.twiml.VoiceResponse();
myTwiml.say({}, 'foo');
myTwiml.toString();

console.log(myTwiml.toString());

// 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);

// verify requests

import express = require('express');
const app = express();

app.get('/', (req: express.Request, res: express.Response) => {
  const isRequestValid = twilio.validateExpressRequest(
    req,
    process.env.TWILIO_AUTH_TOKEN!,
    { url: process.env.TWILIO_WEBHOOK_URL! }
  );

  if (isRequestValid) {
    res.send('Yay');
    return;
  }

  res.send('Nay');
});

@dkundel dkundel requested a review from cjcodes August 29, 2018 11:47
@Hamoonist
Copy link

this commit just saved me! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants