@apidaze/node-red-contrib-apidaze
Version:
Node-RED module for Apidaze
43 lines (30 loc) • 1.13 kB
JavaScript
module.exports = function (RED) {
'use strict';
const { prepareCallMessage } = require('../../helpers/call');
function CallProcessor(config) {
RED.nodes.createNode(this, config);
this.on('input', async (msg, send, done) => {
const { payload } = msg;
const { hookType } = payload;
if (hookType !== 'voiceCall') return null;
const flowContext = this.context() && this.context().flow;
const addressBook = flowContext?.get('addressBook') || {};
const messageStore = flowContext?.get('messageStore') || {};
const newMessage = await prepareCallMessage(msg, addressBook);
const call = msg.payload.call;
const contact = addressBook[call.called_number];
if (contact) {
const entryKey = `${contact.mobileDestination}-${call.called_number}`;
messageStore[entryKey] = {
call_uuid: call.call_uuid
};
if (flowContext.set) {
flowContext.set('messageStore', messageStore);
}
}
send(newMessage);
done();
});
}
RED.nodes.registerType('call-processor', CallProcessor);
};