node-red-contrib-wazo-platform
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -79,2 +79,28 @@ $(() => { | ||
listWazoMoh = (conn, moh_uuid) => { | ||
$('#node-input-moh_name').find('option').remove().end(); | ||
$('#node-input-moh_uuid').val(''); | ||
appendOption("node-input-moh_name", "", "Choose MOH..."); | ||
$('#node-input-moh_name').change(() => { | ||
var selected = $('#node-input-moh_name option:selected').data('uuid'); | ||
$("#node-input-moh_uuid").val(selected); | ||
}); | ||
var params = { | ||
host: conn.host, | ||
port: conn.port, | ||
refreshToken: conn.refreshToken | ||
} | ||
$.post('/wazo-platform/moh', params, (res) => { | ||
res.items.map(item => { | ||
let selected = false; | ||
if (moh_uuid == item.uuid) { selected = true; } | ||
appendOption("node-input-moh_name", item.name, item.name, "uuid", item.uuid, selected); | ||
if (selected) { $("#node-input-moh_uuid").val(item.uuid); } | ||
}); | ||
}); | ||
} | ||
}); |
module.exports = function (RED) { | ||
const { WazoApiClient } = require('@wazo/sdk'); | ||
const fetch = require('node-fetch'); | ||
const https = require("https"); | ||
const agent = new https.Agent({ | ||
rejectUnauthorized: false | ||
}); | ||
@@ -6,2 +13,3 @@ function moh(n) { | ||
wazoConn = RED.nodes.getNode(n.server); | ||
this.moh_uuid = n.moh_uuid; | ||
this.client = wazoConn.client.application; | ||
@@ -12,6 +20,6 @@ | ||
node.on('input', async msg => { | ||
if (msg.payload.call.id) { | ||
call_id = msg.payload.call.id; | ||
application_uuid = msg.payload.application_uuid; | ||
moh_uuid = msg.payload.moh_uuid; | ||
call_id = msg.payload.call ? msg.payload.call.id : msg.payload.call_id; | ||
application_uuid = msg.payload.application_uuid; | ||
if (call_id && application_uuid) { | ||
moh_uuid = node.moh_uuid || msg.payload.moh_uuid; | ||
node.log('Call moh'); | ||
@@ -31,4 +39,47 @@ try { | ||
// FIXME: Remove when SDK will be ready | ||
const confdListMoh = (url, token) => { | ||
const options = { | ||
method: 'GET', | ||
agent: agent, | ||
headers: { | ||
'content-type': 'application/json', | ||
'X-Auth-Token': token | ||
} | ||
}; | ||
return fetch(url, options).then(response => response.json()).then(data => data); | ||
} | ||
RED.httpAdmin.post('/wazo-platform/moh', async function(req, res) { | ||
client = new WazoApiClient({ | ||
server: `${req.body.host}:${req.body.port}`, | ||
agent: agent, | ||
clientId: 'wazo-nodered' | ||
}); | ||
try { | ||
const { ...auth } = await client.auth.refreshToken(req.body.refreshToken); | ||
client.setToken(auth.token); | ||
try { | ||
// FIXME: Remove when SDK will be ready | ||
// const { ...moh } = await client.confd.listMoh(); | ||
const url = `https://${req.body.host}:${req.body.port}/api/confd/1.1/moh`; | ||
const { ...moh } = await confdListMoh(url, auth.token); | ||
res.json(moh); | ||
} | ||
catch(err) { | ||
res.send(err); | ||
throw err; | ||
} | ||
} | ||
catch(err) { | ||
res.send(err); | ||
throw err; | ||
} | ||
}); | ||
RED.nodes.registerType("wazo moh", moh); | ||
} |
{ | ||
"name": "node-red-contrib-wazo-platform", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Node Red module for the Wazo Platform API", | ||
@@ -37,4 +37,7 @@ "main": "index.js", | ||
"hold": "nodes/hold.js", | ||
"unhold": "nodes/unhold.js", | ||
"mute": "nodes/mute.js", | ||
"unmute": "nodes/unmute.js", | ||
"moh": "nodes/moh.js", | ||
"stop moh": "nodes/stop_moh.js", | ||
"new_call": "nodes/new_call.js", | ||
@@ -41,0 +44,0 @@ "node": "nodes/node.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
920655
53
1431
22