actions = util.getActionsByTriggers(data, _.filter(_triggers, {
channel: 'voice'
}));
- data.dataValues.membername = data.channel.split(/\/|-/)[1];
+ data.membername = data.channel.split(/\/|-/)[1];
console.log('After dial update, Actions are ', actions.length);
execActions(actions, data, 'voice', 'outbound', util, voice, mail, cm, jscripty, integration, urlForward);
}
return chatRoom
.getChatVisitor()
.then(function(chatVisitor) {
- var actions = util.getActionsByTriggers(chatVisitor, _.filter(_triggers, {
+ var actions = util.getActionsByTriggers(chatVisitor.dataValues, _.filter(_triggers, {
channel: 'chat'
}));
execActions(actions, _.merge(chatVisitor.dataValues, chatRoom.dataValues), 'chat', null, util, voice, mail, cm, jscripty, integration, urlForward, chat);
});
SmsMessage.afterCreate(function(smsMessage) {
if (smsMessage.status === 'RECEIVED') {
- var actions = util.getActionsByTriggers(smsMessage, _.filter(_triggers, {
+ var actions = util.getActionsByTriggers(smsMessage.dataValues, _.filter(_triggers, {
channel: 'sms'
}));
execActions(actions, smsMessage.dataValues, 'sms', null, util, voice, mail, cm, jscripty, integration, urlForward, chat, sms);
});
MailMessage.afterCreate(function(doc) {
if (doc.status === 'RECEIVED') {
- var actions = util.getActionsByTriggers(doc, _.filter(_triggers, {
+ var actions = util.getActionsByTriggers(doc.dataValues, _.filter(_triggers, {
channel: 'mail',
status: true
}));
- execActions(actions, doc, 'mail', null, util, voice, mail, cm, jscripty, integration, urlForward);
+ execActions(actions, doc.dataValues, 'mail', null, util, voice, mail, cm, jscripty, integration, urlForward);
}
});
})
var channelVariables = _.find(callChannels, {
uniqueid: doc.uniqueid
});
- return channelVariables ? _.merge(_.clone(doc.dataValues), channelVariables.variables) : _.clone(doc.dataValues);
+ return channelVariables ? _.merge(_.clone(doc), channelVariables.variables) : _.clone(doc);
} else {
- return _.clone(doc.dataValues);
+ return _.clone(doc);
}
}
console.log('Executing action "' + action.action + '"');
switch (action.action) {
case 'contactManager':
- cm.manageContact(doc.dataValues, channel);
+ cm.manageContact(doc, channel);
break;
case 'urlForward':
case 'http':
- urlForward.sendRequest(doc.dataValues, channel, action, getActionVariables(doc, channel));
+ urlForward.sendRequest(doc, channel, action, getActionVariables(doc, channel));
break;
case 'jscripty':
- jscripty.manageJscripty(action.data1, doc.dataValues, channel);
+ jscripty.manageJscripty(action.data1, doc, channel);
break;
case 'integration':
case 'motionbar':
- integration.manageEvent(action, doc.dataValues, channel, subtype, getActionVariables(doc, channel));
+ integration.manageEvent(action, doc, channel, subtype, getActionVariables(doc, channel));
break;
case 'tag':
switch (channel) {
case 'mail':
- mail.tag(action, doc.dataValues);
+ mail.tag(action, doc);
break;
case 'chat':
chat.tag(action, doc);
// case 'http': //commented cause urlforward does the same, so we don't repeat the same function
// switch (channel) {
// case 'mail':
- // mail.http(action, doc.dataValues);
+ // mail.http(action, doc);
// break;
// case 'chat':
// chat.http(action, doc);
//
// break;
case 'email':
- mail.email(action, doc.dataValues);
+ mail.email(action, doc);
break;
case 'accountEmail':
switch (channel) {
break;
case 'forward':
- mail.forward(action, doc.dataValues);
+ mail.forward(action, doc);
break;
case 'template':
- mail.template(action, doc.dataValues);
+ mail.template(action, doc);
break;
case 'accountTemplate':
mail.accountTemplate(action, doc);
case 'close':
switch (channel) {
case 'mail':
- mail.close(action, doc.dataValues);
+ mail.close(action, doc);
break;
case 'chat':
chat.close(action, doc);
Util.prototype.getActionsByTriggers = function(doc, triggers) {
var actions = [];
- doc.dataValues.from = doc.dataValues.from ? doc.dataValues.from.split(';') : [];
- doc.dataValues.cc = doc.dataValues.cc ? doc.dataValues.cc.split(';') : [];
- doc.dataValues.to = doc.dataValues.to ? doc.dataValues.to.split(';') : [];
+ doc = doc.datavalues || doc; //in case I forgot something
+ doc.from = doc.from ? doc.from.split(';') : [];
+ doc.cc = doc.cc ? doc.cc.split(';') : [];
+ doc.to = doc.to ? doc.to.split(';') : [];
triggers.forEach(function(trigger) {
if (trigger.status) {
var All = [];
var Any = [];
trigger.All.forEach(function(condition) {
- All.push(checkCondition(condition.dataValues || condition, doc.dataValues));
+ All.push(checkCondition(condition || condition, doc));
});
trigger.Any.forEach(function(condition) {
- Any.push(checkCondition(condition.dataValues || condition, doc.dataValues));
+ Any.push(checkCondition(condition || condition, doc));
});
var allResult = [],
}
}
});
- doc.dataValues.from = doc.dataValues.from.join(';');
- doc.dataValues.cc = doc.dataValues.cc.join(';');
- doc.dataValues.to = doc.dataValues.to.join(';');
+ doc.from = doc.from.join(';');
+ doc.cc = doc.cc.join(';');
+ doc.to = doc.to.join(';');
//return actions array
return actions;
}