node-red-contrib-wazo-platform
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -24,6 +24,3 @@ module.exports = function (RED) { | ||
if (!conn.client.client.token) { | ||
await conn.authenticate(); | ||
} | ||
const token = conn.client.client.token; | ||
const token = await conn.authenticate(); | ||
if (node_uuid) { | ||
@@ -87,4 +84,4 @@ const url = `https://${conn.host}:${conn.port}/api/calld/1.0/applications/${application_uuid}/nodes/${node_uuid}/calls/user`; | ||
try { | ||
const { ...authentication } = await client.auth.refreshToken(req.body.refreshToken); | ||
client.setToken(authentication.token); | ||
const { ...auth } = await client.auth.refreshToken(req.body.refreshToken); | ||
client.setToken(auth.token); | ||
try { | ||
@@ -91,0 +88,0 @@ const { ...users } = await client.confd.listUsers(); |
@@ -38,3 +38,3 @@ module.exports = function (RED) { | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -41,0 +41,0 @@ |
@@ -31,2 +31,4 @@ module.exports = function(RED) { | ||
this.insecure = true; | ||
this.token = false; | ||
this.sessionUuid = false; | ||
@@ -42,9 +44,15 @@ var node = this; | ||
this.authenticate = async function() { | ||
node.log("Connection to Wazo Auth..."); | ||
node.log(`Connection to ${node.host} to get token`); | ||
try { | ||
const { ...result } = await this.client.auth.refreshToken(this.refreshToken, null, this.expiration); | ||
this.client.setToken(result.token); | ||
this.client.setRefreshToken(this.refreshToken); | ||
return result; | ||
const check = await node.client.auth.checkToken(node.token); | ||
if (check !== true) { | ||
node.log(`Get a valid token`); | ||
const { ...auth} = await node.client.auth.refreshToken(node.refreshToken, null, node.expiration); | ||
node.token = auth.token; | ||
node.sessionUuid = auth.sessionUuid; | ||
node.client.setToken(auth.token); | ||
node.client.setRefreshToken(node.refreshToken); | ||
} | ||
return node.token; | ||
} | ||
@@ -66,10 +74,6 @@ catch(err) { | ||
const session = await node.authenticate(); | ||
if (!session) { | ||
node.error('There is no authenticated session'); | ||
} | ||
const token = await node.authenticate(); | ||
const client = new WazoWebSocketClient({ | ||
host: node.host, | ||
token: session.token, | ||
token: token, | ||
events: ['*'], | ||
@@ -89,3 +93,3 @@ version: 2 | ||
if (event == 'auth_session_expire_soon') { | ||
if (message.data.uuid == session.sessionUuid) { | ||
if (message.data.uuid == node.sessionUuid) { | ||
node.log('Session will expire, force Refresh Token'); | ||
@@ -92,0 +96,0 @@ node.client.forceRefreshToken(); |
@@ -65,3 +65,3 @@ module.exports = function (RED) { | ||
const getVoicemail = async (msg, voicemail_id, message_id, user_uuid) => { | ||
const auth = await conn.authenticate(); | ||
const token = await conn.authenticate(); | ||
let url = `https://${conn.host}:${conn.port}/api/calld/1.0/voicemails/${voicemail_id}/messages/${message_id}/recording?download=1`; | ||
@@ -71,3 +71,3 @@ if (node.is_user) { | ||
} | ||
getVoicemailRecording(msg, url, voicemail_id, message_id, auth.token, node, user_uuid); | ||
getVoicemailRecording(msg, url, voicemail_id, message_id, token, node, user_uuid); | ||
} | ||
@@ -74,0 +74,0 @@ |
@@ -11,5 +11,5 @@ module.exports = function (RED) { | ||
node.on('input', async msg => { | ||
if (msg.payload.call.id) { | ||
call_id = msg.payload.call.id; | ||
application_uuid = msg.payload.application_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) { | ||
const result = await node.client.hangupCall(application_uuid, call_id); | ||
@@ -16,0 +16,0 @@ node.log('Call hangup'); |
@@ -26,6 +26,3 @@ module.exports = function (RED) { | ||
if (!conn.client.client.token) { | ||
await conn.authenticate(); | ||
} | ||
const token = conn.client.client.token; | ||
const token = await conn.authenticate(); | ||
@@ -32,0 +29,0 @@ if (node.node_uuid) { |
@@ -20,2 +20,4 @@ module.exports = function (RED) { | ||
const result = await node.client.startPlaybackCall(application_uuid, call_id, node.language, playback_uri); | ||
result.call_id = call_id; | ||
result.application_uuid = application_uuid; | ||
msg.payload = result; | ||
@@ -22,0 +24,0 @@ node.send(msg); |
@@ -9,2 +9,3 @@ module.exports = function (RED) { | ||
this.ws = this.conn; | ||
this.client = this.conn.client.chatd; | ||
@@ -41,4 +42,4 @@ var node = this; | ||
const initState = async () => { | ||
const client = await checkToken(); | ||
const presence = await client.getContactStatusInfo(node.user_uuid); | ||
const token = await node.conn.authenticate(); | ||
const presence = await node.client.getContactStatusInfo(node.user_uuid); | ||
setNodeStatus(presence.state, presence.status); | ||
@@ -49,4 +50,4 @@ } | ||
try { | ||
const client = await checkToken(); | ||
client.updateState(user_uuid, state); | ||
const token = await node.conn.authenticate(); | ||
node.client.updateState(user_uuid, state); | ||
node.log(`Update state presence for ${user_uuid} to ${state}`); | ||
@@ -62,4 +63,4 @@ setNodeStatus(state, undefined); | ||
try { | ||
const client = await checkToken(); | ||
client.updateStatus(user_uuid, state, status); | ||
const token = await node.conn.authenticate(); | ||
node.client.updateStatus(user_uuid, state, status); | ||
node.log(`Update state/status presence for ${user_uuid} to ${state}/${status}`); | ||
@@ -73,15 +74,2 @@ setNodeStatus(state, status); | ||
const checkToken = async () => { | ||
if (!node.conn.client.client.token) { | ||
try { | ||
const { ...result } = await node.conn.authenticate(); | ||
node.conn.client.setToken(result.token); | ||
} | ||
catch(err) { | ||
node.error(err); | ||
} | ||
} | ||
return node.conn.client.chatd; | ||
} | ||
initState(); | ||
@@ -88,0 +76,0 @@ } |
@@ -25,4 +25,4 @@ module.exports = function (RED) { | ||
node.status({fill:"blue", shape:"dot", text: `Request to ${node.serviceName}!`}); | ||
const auth = await node.conn.authenticate(); | ||
const result = await apiRequest(url, method, auth.token, body); | ||
const token = await node.conn.authenticate(); | ||
const result = await apiRequest(url, method, token, body); | ||
msg.payload = result; | ||
@@ -29,0 +29,0 @@ node.send(msg); |
@@ -45,8 +45,6 @@ module.exports = function (RED) { | ||
initListTrunks(); | ||
} | ||
// FIXME: Remove when SDK will be ready | ||
const listTrunks = (url, token) => { | ||
const confdListTrunks = (url, token) => { | ||
const options = { | ||
@@ -72,4 +70,4 @@ method: 'GET', | ||
try { | ||
const { ...authentication } = await client.auth.refreshToken(req.body.refreshToken); | ||
client.setToken(authentication.token); | ||
const { ...auth } = await client.auth.refreshToken(req.body.refreshToken); | ||
client.setToken(auth.token); | ||
try { | ||
@@ -80,3 +78,3 @@ // FIXME: Remove when SDK will be ready | ||
const url = `https://${req.body.host}:${req.body.port}/api/confd/1.1/trunks`; | ||
const { ...trunks } = await listTrunks(url, authentication.token); | ||
const { ...trunks } = await confdListTrunks(url, auth.token); | ||
res.json(trunks); | ||
@@ -83,0 +81,0 @@ } |
{ | ||
"name": "node-red-contrib-wazo-platform", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Node Red module for the Wazo Platform API", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@wazo/sdk": "0.27.3", | ||
"@wazo/sdk": "0.28.1", | ||
"request": "^2.88.2", | ||
@@ -37,2 +37,6 @@ "ws": "^7.2.1" | ||
"hangup": "nodes/hangup.js", | ||
"hold": "nodes/hold.js", | ||
"mute": "nodes/mute.js", | ||
"moh": "nodes/moh.js", | ||
"new_call": "nodes/new_call.js", | ||
"node": "nodes/node.js", | ||
@@ -39,0 +43,0 @@ "playback": "nodes/playback.js", |
911819
47
1288
20
+ Added@wazo/sdk@0.28.1(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedsip.js@0.15.10(transitive)
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/node@22.13.4(transitive)
- Removed@wazo/sdk@0.27.3(transitive)
- Removedglobby@10.0.2(transitive)
- Removedsip.js@0.14.6(transitive)
- Removedundici-types@6.20.0(transitive)
Updated@wazo/sdk@0.28.1