-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from jandusek/v1.0
V1.0
- Loading branch information
Showing
26 changed files
with
22,682 additions
and
4,197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ACCOUNT_SID=ACxxx | ||
AUTH_TOKEN=xxx | ||
SYNC_API_KEY=SKxxx | ||
SYNC_API_SECRET=xxx | ||
API_KEY=SKxxx | ||
API_SECRET=xxx | ||
CHAT_SERVICE_SID=ISxxx | ||
TWILIO_NUMBER=+1xxx | ||
TWIML_APP_SID=APxxx | ||
SECRET=some_password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
exports.handler = (context, event, callback) => { | ||
let response = new Twilio.twiml.VoiceResponse(); | ||
const dial = response.dial(); | ||
dial.client('client' + context.TWILIO_NUMBER); | ||
callback(null, response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,48 @@ | ||
const isEnabled = true; | ||
const isEnabled = true; // master switch for programmatic enabling/disabling of the client | ||
|
||
exports.handler = function (context, event, callback) { | ||
const AccessToken = Twilio.jwt.AccessToken; | ||
const ChatGrant = AccessToken.ChatGrant; | ||
const VoiceGrant = AccessToken.VoiceGrant; | ||
let response = new Twilio.Response(); | ||
response.setHeaders({ | ||
"Access-Control-Allow-Origin": "*" | ||
}); | ||
|
||
// if running locally (i.e. testing), enable any originator for CORS | ||
if (context.path === undefined) | ||
response.setHeaders({ | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS' | ||
}); | ||
|
||
// check master switch | ||
if (!isEnabled) { | ||
response.setStatusCode(404); | ||
callback(null, response); | ||
} else { | ||
const token = new AccessToken( | ||
context.ACCOUNT_SID, | ||
context.SYNC_API_KEY, | ||
context.SYNC_API_SECRET, | ||
{ ttl: 3600 } // tokenAboutToExpire event is triggered 3 minutes before expiration to this gives each token ~30s of effective lifetime | ||
); | ||
const chatGrant = new ChatGrant({ | ||
serviceSid: context.CHAT_SERVICE_SID, | ||
}); | ||
token.addGrant(chatGrant); | ||
token.identity = "build-client"; | ||
response.setBody(token.toJwt()); | ||
callback(null, response); | ||
response.setBody('This client is currently disabled'); | ||
return callback(null, response); | ||
} | ||
|
||
}; | ||
// check secret | ||
if (event.secret !== context.SECRET) { | ||
response.setStatusCode(401); | ||
response.setBody('Invalid secret'); | ||
return callback(null, response); | ||
} | ||
|
||
const token = new AccessToken( | ||
context.ACCOUNT_SID, | ||
context.API_KEY, | ||
context.API_SECRET, | ||
{ ttl: 3600 } // tokenAboutToExpire event is triggered 3 minutes before expiration to this gives each token ~57m of effective lifetime | ||
); | ||
const chatGrant = new ChatGrant({ | ||
serviceSid: context.CHAT_SERVICE_SID | ||
}); | ||
const voiceGrant = new VoiceGrant({ | ||
outgoingApplicationSid: process.env.TWIML_APP_SID, | ||
incomingAllow: true | ||
}); | ||
token.addGrant(chatGrant); | ||
token.addGrant(voiceGrant); | ||
token.identity = 'client' + context.TWILIO_NUMBER; | ||
response.setBody(token.toJwt()); | ||
return callback(null, response); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.