Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* this route creates tasks for our customers */
const twilio = require('twilio')
const AccessToken = twilio.jwt.AccessToken
const VideoGrant = twilio.jwt.AccessToken.VideoGrant
const ChatGrant = twilio.jwt.AccessToken.ChatGrant
const taskrouterHelper = require('./helpers/taskrouter-helper.js')
const chatHelper = require('./helpers/chat-helper.js')
module.exports.createCallback = function (req, res) {
taskrouterHelper.createTask(req.configuration.twilio.workflowSid, req.body)
.then(task => {
res.status(200).end()
}).catch(error => {
res.status(500).send(res.convertErrorToJSON(error))
})
}
module.exports.createChat = function (req, res) {
module.exports.createWorkerCapabilityToken = function (sid) {
const workerCapability = new TaskRouterCapability({
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
workspaceSid: process.env.TWILIO_WORKSPACE_SID,
channelId: sid,
ttl: 3600,
})
const eventBridgePolicies = twilio.jwt.taskrouter.util.defaultEventBridgePolicies(process.env.TWILIO_ACCOUNT_SID, sid)
const workspacePolicies = [
// Workspace fetch Policy
buildWorkspacePolicy(),
// Workspace subresources fetch Policy
buildWorkspacePolicy({ resources: ['**'] }),
// Workspace resources update Policy
buildWorkspacePolicy({ resources: ['**'], method: 'POST' }),
]
eventBridgePolicies.concat(workspacePolicies).forEach(policy => {
workerCapability.addPolicy(policy)
})
return workerCapability
}
'use strict';
/**
* Load Twilio configuration from .env config file - the following environment
* variables should be set:
* process.env.TWILIO_ACCOUNT_SID
* process.env.TWILIO_API_KEY
* process.env.TWILIO_API_SECRET
*/
require('dotenv').load();
var http = require('http');
var path = require('path');
var AccessToken = require('twilio').jwt.AccessToken;
var VideoGrant = AccessToken.VideoGrant;
var express = require('express');
var randomName = require('./randomname');
// Max. period that a Participant is allowed to be in a Room (currently 14400 seconds or 4 hours)
const MAX_ALLOWED_SESSION_DURATION = 14400;
// Create Express webapp.
var app = express();
// Set up the paths for the examples.
[
'bandwidthconstraints',
'codecpreferences',
'dominantspeaker',
'localvideofilter',
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const taskrouter = require('twilio').jwt.taskrouter;
const util = taskrouter.util;
const TaskRouterCapability = taskrouter.TaskRouterCapability;
const Policy = TaskRouterCapability.Policy;
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const workspaceSid = 'WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const workerSid = 'WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const TASKROUTER_BASE_URL = 'https://taskrouter.twilio.com';
const version = 'v1';
const capability = new TaskRouterCapability({
accountSid: accountSid,
authToken: authToken,
const AccessToken = require('twilio').jwt.AccessToken;
const ChatGrant = AccessToken.ChatGrant;
// Used when generating any kind of tokens
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';
// Used specifically for creating Chat tokens
const serviceSid = 'ISxxxxxxxxxxxxx';
const appName = 'HipFlowSlackDockRC';
const identity = 'user@example.com';
const deviceId = 'someiosdeviceid';
const endpointId = `${appName}:${identity}:${deviceId}`;
// Create a "grant" which enables a client to use Chat as a given user,
// on a given device
const http = require('http');
const express = require('express');
const bodyParser = require('body-parser');
const ClientCapability = require('twilio').jwt.ClientCapability;
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/token', (req, res) => {
// put your Twilio API credentials here
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
// put your Twilio Application Sid here
const appSid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const capability = new ClientCapability({
accountSid: accountSid,
authToken: authToken,
});
'use strict';
var twilio = require('twilio');
var AccessToken = twilio.jwt.AccessToken;
var ChatGrant = AccessToken.ChatGrant;
function TokenProvider(credentials) {
Object.defineProperties(this, {
accountSid: {
enumerable: true,
value: credentials.accountSid
},
signingKeySid: {
enumerable: true,
value: credentials.signingKeySid
},
signingKeySecret: {
enumerable: true,
value: credentials.signingKeySecret || credentials.authToken
},
const twilio = require('twilio');
const config = require('../config');
const AccessToken = twilio.jwt.AccessToken;
const ChatGrant = AccessToken.ChatGrant;
function getTwilioToken(req, res) {
const twilio = config.twilio;
const userCard = req.userCard;
const endpointId = `${config.app.name}:${userCard.identity}:${userCard.data.deviceId}`;
const charGrant = new ChatGrant({
serviceSid: twilio.ipmServiceSid,
endpointId
});
const token = new AccessToken(twilio.accountSid, twilio.apiKey, twilio.apiSecret);
token.addGrant(charGrant);
token.identity = userCard.identity;
res.json({ twilioToken: token.toJwt() });
const twilio = require('twilio');
const AccessToken = twilio.jwt.AccessToken;
const { ChatGrant, VideoGrant, VoiceGrant } = AccessToken;
const generateToken = config => {
return new AccessToken(
config.twilio.accountSid,
config.twilio.apiKey,
config.twilio.apiSecret
);
};
const chatToken = (identity, config) => {
const chatGrant = new ChatGrant({
serviceSid: config.twilio.chatService
});
const token = generateToken(config);
token.addGrant(chatGrant);
const twilio = require('twilio')
const AccessToken = twilio.jwt.AccessToken
const client = twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN
)
const taskrouterHelper = require('./helpers/taskrouter-helper.js')
const clientHelper = require('./helpers/client-helper.js')
module.exports.login = function (req, res) {
const friendlyName = req.body.worker.friendlyName
const filter = { friendlyName: friendlyName }
client.taskrouter
.workspaces(process.env.TWILIO_WORKSPACE_SID)