File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/components/inbound/models.js
// jshint esversion: 6
var Backbone = require('backbone');
var { Agents } = require('../agents/agents');
const API_ROOT = '/api/inbound';
var PhoneNumberRoutings = Backbone.Collection.extend({
url: `${API_ROOT}/routings`,
parse: function (response) {
return response.data;
}
});
var PhoneNumberRouting = Backbone.Model.extend({
urlRoot: `${API_ROOT}/routings`,
defaults: {
'typePn': 'local',
'source': null,
'friendlyName': 'Default Phone Number',
// Possible values: 'tracking' or 'priority'
'type': 'tracking',
'channel': 'Organic Search',
'phoneNumber': null,
'callerId': false,
'subscriptionPlan': '',
'routingConfig': null, // -> see below
'notificationConfig': null, // -> see below
},
initialize: function () {
if (!this.get('routingConfig')) {
this.set('routingConfig', new RoutingConfig(), { silent: true });
}
if (!this.get('notificationConfig')) {
this.set('notificationConfig', new NotificationConfig(), { silent: true });
}
},
toJSON: function () {
var result = Backbone.Model.prototype.toJSON.call(this);
result.routingConfig = this.get('routingConfig').toJSON();
result.notificationConfig = this.get('notificationConfig').toJSON();
return result;
},
// Not safe to use on its own
parse: function (attrs) {
var result = _.extend({}, attrs);
if ('routingConfig' in attrs) {
let model = this.get('routingConfig');
if (!model) {
model = new RoutingConfig(attrs.routingConfig, { parse: true });
} else {
let newAttrs = model.parse(attrs.routingConfig);
model.set(newAttrs, { silent: true });
}
result.routingConfig = model;
}
if ('notificationConfig' in attrs) {
let model = this.get('notificationConfig');
if (!model) {
model = new NotificationConfig(attrs.notificationConfig, { parse: true });
} else {
let newAttrs = model.parse(attrs.notificationConfig);
model.set(newAttrs, { silent: true });
}
result.notificationConfig = model;
}
return result;
}
});
var RoutingConfig = Backbone.Model.extend({
defaults: {
language: 'en',
greetingMessage: false,
whisperMessageType: '',
whisperMessage: '',
// 'default' or 'digit'
routingType: 'default',
digitWhisperMessageType: '',
digitWhisperMessage: '',
noDigitWhisperMessageType: '',
noDigitWhisperMessage: '',
playHoldMusic: false,
callerIdPn: false, // If true, it will use the tracking pn as caller id. If false it will use the caller's caller id
customHoldMusic: false,
digitPrompt: false,
recordCalls: false,
clientVoicemail: false, // If true, the timeout will on transfers will be longer to reach clients own vm
voicemail: false,
voicemailMessageType: '',
voicemailMessage: 'Sorry, we are not available at the moment. Please leave a voice message and we\'ll get back to you as soon as possible.',
callBack: false,
firstCallBack: '',
secondCallBack: '',
thirdCallBack: '',
callBackMessage: false,
callBackTextType: '',
callBackText: 'Hello. We\'re calling you back since we missed your call a while ago.',
hiddenInformation: '',
notifyAdf: false,
notifyAdfCustom: '',
configSMSSetup: false,
SMSAutoReply: false,
SMSAutoReplyText: 'Thanks for the message. We\'ll be in touch.',
SMSAutoReplyImage: false,
SMSAutoReplyImageUrl: '',
MissedCallAutoReply: false,
MissedCallAutoReplyText: 'Sorry we missed your call. Want us to reply by text message?',
SMSRuleOne: false,
SMSRuleOneKeyword: '',
SMSRuleOneAction: '',
SMSRuleOneRecipientType: '',
SMSRuleOneRecipientCustom: '',
SMSRuleOneRecipientAgent: '',
SMSRuleOneCallAgent: '',
SMSRuleOneSMSBody: '',
SMSRuleOneEmails: '',
SMSRuleOneEmailAgent: '',
SMSRuleOneEmailBody: '',
transcribeAnsweredCall: false,
transcribeVoiceMail: false,
},
initialize: function () {
var digitRoutings = this.get('digitRoutings');
if (!digitRoutings) {
digitRoutings = new Backbone.Collection([ ], {
model: Routing
});
this.set('digitRoutings', digitRoutings, { silent: true });
}
var defaultRouting = this.get('defaultRouting');
if (!defaultRouting) {
this.set('defaultRouting', new Routing(), { silent: true });
}
},
parse: function (attrs) {
var result = _.extend({}, attrs);
if ('digitRoutings' in attrs) {
var oldDigitRoutings = this.get('digitRoutings');
if (!oldDigitRoutings) {
result.digitRoutings = new Backbone.Collection(attrs.digitRoutings, {
model: Routing,
parse: true
});
} else {
oldDigitRoutings.set(attrs.digitRoutings, { parse: true });
result.digitRoutings = oldDigitRoutings;
}
}
if ('defaultRouting' in attrs) {
var oldDefaultRouting = this.get('defaultRouting');
if (!oldDefaultRouting) {
result.defaultRouting = new Routing(attrs.defaultRouting, { parse: true });
} else {
var newAttrs = oldDefaultRouting.parse(attrs.defaultRouting);
oldDefaultRouting.set(newAttrs, { silent: true });
result.defaultRouting = oldDefaultRouting;
}
}
return result;
},
toJSON: function () {
var result = Backbone.Model.prototype.toJSON.call(this);
result.digitRoutings = this.get('digitRoutings').toJSON();
result.defaultRouting = this.get('defaultRouting').toJSON();
return result;
}
});
var Routing = Backbone.Model.extend({
defaults: {
// The routing name (auto-generated)
name: 'Default routing',
// The dial digit that the lead presses to call this routing, or 'null' for
// the default routing
dialDigit: null,
// 'sequence', 'shuffle' or 'simultaneous'
callOrder: 'sequence',
// The collection of agents for this routing
agents: null,
// Number of times to retry the routing
retryRouting: 0,
},
initialize: function () {
this.set('agents', this.get('agents') || new Agents(), {
silent: true
});
},
// Not safe to use on its own
parse: function (args) {
var result = _.extend({}, args);
var agents = this.get('agents') || new Agents();
if ('agents' in args) {
agents.set(args.agents);
}
result.agents = agents;
return result;
}
});
var NotificationConfig = Backbone.Model.extend({
defaults: {
// Possible values: 'all', 'missed', 'none'
'notifyLeads': 'all',
'notifyAllMe': true,
'notifyAllAgents': false,
'notifyAllCustom': '',
'notifyMissedMe': true,
'notifyMissedAgents': false,
'notifyMissedCustom': ''
}
});
module.exports = { PhoneNumberRouting, Routing };