-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (27 loc) · 750 Bytes
/
server.js
File metadata and controls
34 lines (27 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require('dotenv').config();
const Twilio = require('twilio');
const express = require('express');
const app = express();
const AccessToken = Twilio.jwt.AccessToken;
const ChatGrant = AccessToken.ChatGrant;
app.get('/token/:identity', (req, res) => {
const identity = req.params.identity;
const token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET,
);
token.identity = identity;
token.addGrant(
new ChatGrant({
serviceSid: process.env.TWILIO_CHAT_SERVICE_SID,
}),
);
res.send({
identity: token.identity,
jwt: token.toJwt(),
});
});
app.listen(3001, function () {
console.log('Programmable Chat server running on port 3001!');
});