mirror of
https://github.com/jambonz/jambonz-node.git
synced 2026-10-30 23:24:28 +00:00
add initial support for REST
This commit is contained in:
1 parent
d0972145f0
commit
356ae693cc
6 files changed
+113
-6
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user