Skip to content

Commit efca198

Browse files
Update voice
1 parent ac337e8 commit efca198

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/commands/token/voice.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
22
const Twilio = require('twilio');
33
const createToken = require('../../helpers/accessToken.js');
44
const globalFlags = require('../../helpers/globalFlags.js');
5-
const { voiceFlags, validateTwimlAppSid, validatePushCredentialSid } = require('../../helpers/voiceGlobals.js');
5+
const { voiceFlags } = require('../../helpers/voiceGlobals.js');
6+
const { validateSid } = require('../../helpers/validation-helpers.js');
67

78
class VoiceTokenGenerator extends TwilioClientCommand {
89
constructor(argv, config) {
@@ -15,27 +16,31 @@ class VoiceTokenGenerator extends TwilioClientCommand {
1516
await super.run();
1617

1718
const accessToken = createToken.call(this);
19+
// all flags
20+
const voiceAppSid = await this.flags['voice-app-sid'];
21+
const pushCredentialSid = await this.flags['push-credential-sid'];
22+
const incomingAllow = await this.flags['allow-incoming'];
1823

19-
if (!validateTwimlAppSid(this.flags['voice-app-sid'])) {
24+
if (!validateSid('AP', voiceAppSid)) {
2025
this.logger.error(
2126
'Invalid TwiML Application SID, must look like APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2227
);
2328
process.exit(1);
2429
}
2530

26-
let pushCredentialSid = this.flags['push-credential-sid'];
27-
if (pushCredentialSid && !validatePushCredentialSid(pushCredentialSid)) {
31+
// logic for optional pushCredential
32+
if (pushCredentialSid && !validateSid('CR', pushCredentialSid)) {
2833
this.logger.error(
2934
'Invalid Push Credential SID, must look like CRxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
3035
);
3136
process.exit(1);
3237
}
3338

34-
let incomingAllow = (this.flags['allow-incoming'] == 'true');
35-
let voiceGrant = new Twilio.jwt.AccessToken.VoiceGrant({
36-
outgoingApplicationSid: this.flags['voice-app-sid'],
39+
const voiceGrant = new Twilio.jwt.AccessToken.VoiceGrant({
40+
outgoingApplicationSid: voiceAppSid,
3741
incomingAllow
3842
});
43+
3944
if (pushCredentialSid) {
4045
voiceGrant.pushCredentialSid = pushCredentialSid;
4146
}

src/helpers/voiceGlobals.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,4 @@ const voiceFlags = {
1717
})
1818
};
1919

20-
const validateTwimlAppSid = function(sid) {
21-
return (
22-
sid.startsWith('AP') &&
23-
sid.length === 34
24-
);
25-
}
26-
27-
const validatePushCredentialSid = function(sid) {
28-
return (
29-
sid.startsWith('CR') &&
30-
sid.length === 34
31-
);
32-
}
33-
34-
module.exports = { voiceFlags, validateTwimlAppSid, validatePushCredentialSid };
20+
module.exports = { voiceFlags };

0 commit comments

Comments
 (0)