forked from kevinthompson/react-programmable-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 727 Bytes
/
server.js
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
require('dotenv').load()
const Twilio = require('twilio')
const chance = new require('chance')()
const express = require('express')
const app = express()
const AccessToken = Twilio.jwt.AccessToken
const ChatGrant = AccessToken.ChatGrant
app.get('/token', function (req, res) {
const token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET,
)
token.identity = chance.name()
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 token server listening on port 3001!')
})