node-bandwidth-extras
Helper functions and middlewares for node-bandwidth. Read more documentation here.
Install
Run
npm install @bandwidth/node-bandwidth-extra
Examples
Helpers
const {application, phoneNumber} = require("@bandwidth/node-bandwidth-extra");
const appId = await application.getOrCreateApplication(api, 'My app', 'my.domain.com');
const number = await phoneNumber.getOrCreatePhoneNumber(api, appId, {name: 'Support', areaCode: '910'});
Middlewares
Koa
const {middlewares} = require("@bandwidth/node-bandwidth-extra");
const app = new Koa();
app.use(middlewares.koa({
name: 'My app',
auth: {userId: 'bandwidthUserId', apiToken: 'bandwidthApiToken', apiSecret: 'bandwidthSecret'},
phoneNumber: {
phoneType: 'local',
areaCode: '910'
},
callCallback: async (data, ctx) => {
if(data.eventType === 'answer' && ctx.phoneNumber === data.to){
console.log('Answered');
}
}
}));
app.use(async (ctx, next) => {
console.log(ctx.phoneNumber);
await next();
});
Express
const {middlewares} = require("@bandwidth/node-bandwidth-extra");
const app = express();
app.use(middlewares.express({
name: 'My app',
auth: {userId: 'bandwidthUserId', apiToken: 'bandwidthApiToken', apiSecret: 'bandwidthSecret'},
phoneNumber: {
phoneType: 'local',
areaCode: '910'
},
callCallback: async (data, req) => {
if(data.eventType === 'answer' && req.phoneNumber === data.to){
console.log('Answered');
}
}
}));
app.use((req, res, next) => {
console.log(req.phoneNumber);
next();
});