Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilio-remote-cli

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio-remote-cli - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

53

lib/index.js

@@ -1,2 +0,2 @@

const { prompt } = require('enquirer');
const { prompt, Select } = require('enquirer');
const {

@@ -63,22 +63,41 @@ init,

const twiliocc = new TwilioCC(...config);
const callSid = await twiliocc[operation['operation']].call(
twiliocc,
destination.number,
message
);
let taskSid;
if (operation.operation === 'call') {
await twiliocc.getCallStatus(callSid);
const callOperation = await prompt(questions.callQuestion);
if (operation.operation === 'sms') {
taskSid = await twiliocc.sms(destination.number, message);
await twiliocc.getSmsStatus(taskSid);
return;
}
if (!callOperation.action) {
return;
}
let callStatus;
callSid = await twiliocc.call(destination.number);
if (callOperation.action == 'drop') {
await twiliocc.terminateCall(callSid);
}
const promptInput = new Select({
name: 'dropCall',
choices: ['Drop call'],
separator: () => '',
header: () => callStatus,
message: state =>
state.submitted
? 'Call ended'
: `Press return to end the call once you're done.`
});
return;
}
promptInput
.once('close', () => promptInput.clear())
.once('run', () => {
setInterval(async () => {
const call = await twiliocc.keepCallingLoop(callSid);
if (!call) {
promptInput.cancel();
}
callStatus = call;
promptInput.render();
}, 500);
});
await promptInput.run();
await twiliocc.dropCall(callSid);
} catch (err) {

@@ -85,0 +104,0 @@ console.log(err.message || '');

@@ -14,13 +14,2 @@ module.exports = {

callQuestion: {
type: 'select',
name: 'action',
message: 'Select an operation',
initial: 0,
choices: [
{ name: 'keep', message: 'Keep ringing', value: 'keep' },
{ name: 'drop', message: 'Drop the call', value: 'drop' }
]
},
destinationNumber: lastUsedNumber => ({

@@ -27,0 +16,0 @@ type: 'input',

const twilio = require('twilio');
const axios = require('axios');
const chalk = require('chalk');
const ora = require('ora');

@@ -14,13 +15,11 @@ module.exports.TwilioCC = class TwilioCC {

async sms(to, body) {
try {
await this.client.messages.create({
from: this.phoneNumber,
to,
body
});
} catch (err) {
console.log(err);
}
let message;
console.log('Message sent');
message = await this.client.messages.create({
from: this.phoneNumber,
to,
body
});
return message.sid;
}

@@ -31,58 +30,64 @@

try {
task = await this.client.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
from: this.phoneNumber,
to
});
task = await this.client.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
from: this.phoneNumber,
to
});
if (!(task.status && task.sid)) {
throw 'Something went wrong. Please try again or check your Twilio credentials.';
}
} catch (err) {
throw err;
if (!(task.status && task.sid)) {
throw 'Something went wrong. Please try again or check your Twilio credentials.';
}
console.log(`Calling ${to}...`);
return new Promise(res => {
setTimeout(() => res(task.sid), 500);
});
return task.sid;
}
async getCallStatus(callSid) {
const baseURL = `https://api.twilio.com`;
const auth = Buffer.from(`${this.accountSid}:${this.authToken}`).toString(
'base64'
);
async getSmsStatus(taskId) {
const message = await this.client.messages(taskId).fetch();
const callStatusReq = axios.create({
baseURL,
timeout: 1500,
headers: { Authorization: `Basic ${auth}` }
});
const copy = `${chalk.cyan('Sending message to:')} ${message.to}...`;
const spinner = ora(copy).start();
return new Promise(res => {
callStatusReq
.get(`/2010-04-01/Accounts/${this.accountSid}/Calls/${callSid}.json`)
.then(function(response) {
if (response.status !== 200) {
throw 'Server error';
const checkDelivery = async () =>
new Promise(async res => {
const sms = await this.client.messages(taskId).fetch();
setTimeout(() => {
if (sms.status === 'delivered') {
spinner.clear();
return res();
}
setTimeout(() => res(), 500);
})
.catch(function(error) {
// handle error
console.log(error);
return;
});
checkDelivery(taskId);
}, 1000);
});
await checkDelivery(taskId);
}
async dropCall(callSid) {
const callTask = await this.client.calls(callSid);
return callTask.update({
status: 'completed'
});
}
async terminateCall(callSid) {
const task = await this.client.calls(callSid);
async keepCallingLoop(callSid) {
const taskDetails = await this.client.calls(callSid).fetch();
const callStatus = taskDetails.status;
const completedStatus = ['canceled', 'completed', 'failed'];
const callMessage = `Calling ${taskDetails.to}`;
return await task.update({ status: 'completed' });
if (callStatus === 'queued') {
return `${callMessage}...`;
}
if (completedStatus.includes(callStatus)) {
return false;
}
if (callStatus !== 'queued') {
return `${callMessage}: ${callStatus}`;
}
}
};
{
"name": "twilio-remote-cli",
"version": "0.3.0",
"version": "0.3.1",
"description": "A remote control for your Twilio API",

@@ -32,6 +32,7 @@ "main": "index.js",

"dependencies": {
"axios": "^0.18.0",
"enquirer": "^2.0.7",
"chalk": "^2.4.2",
"enquirer": "^2.3.0",
"meow": "^5.0.0",
"nconf": "^0.10.0",
"ora": "^3.2.0",
"twilio": "^3.23.2",

@@ -38,0 +39,0 @@ "update-notifier": "^2.5.0"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc