add initial support for REST

This commit is contained in:
Dave Horton committed 2021-02-18 15:57:46 -05:00
1 parent d0972145f0
commit 356ae693cc
6 files changed
+113 -6

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
const assert = require('assert');
class Calls {
constructor(accountSid, apiKey, opts) {
this.accountSid = accountSid;
this.apiKey = apiKey;
['post', 'put', 'get', 'del'].forEach((m) => this[m] = opts[m]);
}
async update(callSid, opts) {
const {call_hook, call_status, listen_status, mute_status, whisper} = opts;
assert.ok(call_hook || call_status || listen_status || mute_status || whisper,
`calls.update: invalid request ${JSON.stringify(opts)}`);
if (call_status) assert.ok(['completed', 'no-answer'].includes(call_status),
`invalid call_status: ${call_status}, must be 'completed' or 'no-answer'`);
if (mute_status) assert.ok(['mute', 'unmute'].includes(mute_status),
`invalid mute_status: ${mute_status}, must be 'mute' or 'unmute'`);
if (whisper) assert.ok(whisper.verb,
`invalid whisper: ${JSON.stringify(whisper)}, must be a 'play' or 'say' verb`);
await this.post(`Accounts/${this.accountSid}/Calls/${callSid}`, opts);
}
}
module.exports = Calls;