cc320b84705ae0eeb4d91cceb9e8a508626b86f0
[motion2.git] / server / services / ami / ami.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xff18=['close','exports','asterisk-manager','moment','util','lodash','../../config/logger','ami','../../config/environment','port','username','asterisk','password','keepConnected','Action','promisify','action','error','format','Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s','inspect','actionSipShowRegistry','actionDeviceStateList','actionSipPeerStatus','sippeerstatus','actionQueueSummary','actionCoreShowChannels','info','once','connect','shutdown','Fullybooted\x20\x22%s\x22\x20to\x20%s:%s','resolve','then','log'];(function(_0x407178,_0x7769ef){var _0x58cf16=function(_0x4f749f){while(--_0x4f749f){_0x407178['push'](_0x407178['shift']());}};_0x58cf16(++_0x7769ef);}(_0xff18,0x13d));var _0x8ff1=function(_0x494d1f,_0x3f72ff){_0x494d1f=_0x494d1f-0x0;var _0x457b6e=_0xff18[_0x494d1f];return _0x457b6e;};'use strict';var Manager=require(_0x8ff1('0x0'));var BPromise=require('bluebird');var moment=require(_0x8ff1('0x1'));var util=require(_0x8ff1('0x2'));var _=require(_0x8ff1('0x3'));var logger=require(_0x8ff1('0x4'))(_0x8ff1('0x5'));var config=require(_0x8ff1('0x6'));var ami=new Manager(config['asterisk'][_0x8ff1('0x7')],config['asterisk']['ip'],config['asterisk'][_0x8ff1('0x8')],config[_0x8ff1('0x9')][_0x8ff1('0xa')],!![]);ami[_0x8ff1('0xb')]();ami[_0x8ff1('0xc')]=BPromise[_0x8ff1('0xd')](ami[_0x8ff1('0xe')]);function error(_0x303c4e){logger[_0x8ff1('0xf')](util[_0x8ff1('0x10')](_0x8ff1('0x11'),config[_0x8ff1('0x9')][_0x8ff1('0x8')],config[_0x8ff1('0x9')]['ip'],config['asterisk'][_0x8ff1('0x7')],util[_0x8ff1('0x12')](_0x303c4e,![],null)));}function close(){logger[_0x8ff1('0xf')](util[_0x8ff1('0x10')]('Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s',config[_0x8ff1('0x9')]['username'],config[_0x8ff1('0x9')]['ip'],config[_0x8ff1('0x9')][_0x8ff1('0x7')]));}ami[_0x8ff1('0x13')]=function(){return function(){return ami['Action']({'action':'sipshowregistry'});};};ami[_0x8ff1('0x14')]=function(){return function(){return ami[_0x8ff1('0xc')]({'action':'devicestatelist'});};};ami[_0x8ff1('0x15')]=function(){return function(){return ami[_0x8ff1('0xc')]({'action':_0x8ff1('0x16')});};};ami[_0x8ff1('0x17')]=function(){return function(){return ami['Action']({'action':'queuesummary'});};};ami[_0x8ff1('0x18')]=function(){return function(){return ami[_0x8ff1('0xc')]({'action':'coreshowchannels'});};};function connect(_0x4f1228){logger[_0x8ff1('0x19')](util[_0x8ff1('0x10')]('Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s',config['asterisk'][_0x8ff1('0x8')],config[_0x8ff1('0x9')]['ip'],config[_0x8ff1('0x9')][_0x8ff1('0x7')]));ami[_0x8ff1('0x1a')](_0x8ff1('0xf'),error);ami[_0x8ff1('0x1a')]('close',close);}ami['on'](_0x8ff1('0x1b'),connect);ami['on'](_0x8ff1('0x1c'),function(_0x550f19){logger['info'](util[_0x8ff1('0x10')]('Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s',config[_0x8ff1('0x9')]['username'],config[_0x8ff1('0x9')]['ip'],config[_0x8ff1('0x9')][_0x8ff1('0x7')],util[_0x8ff1('0x12')](_0x550f19,![],null)));});ami['on']('fullybooted',function(_0x500dd7){logger[_0x8ff1('0x19')](util[_0x8ff1('0x10')](_0x8ff1('0x1d'),config[_0x8ff1('0x9')][_0x8ff1('0x8')],config[_0x8ff1('0x9')]['ip'],config['asterisk'][_0x8ff1('0x7')]));return BPromise[_0x8ff1('0x1e')]()[_0x8ff1('0x1f')](ami[_0x8ff1('0x13')]())[_0x8ff1('0x1f')](ami[_0x8ff1('0x14')]())[_0x8ff1('0x1f')](ami[_0x8ff1('0x15')]())[_0x8ff1('0x1f')](ami['actionQueueSummary']())[_0x8ff1('0x1f')](ami['actionCoreShowChannels']())['catch'](function(_0x4af70d){console[_0x8ff1('0x20')](_0x4af70d);});});ami[_0x8ff1('0x1a')](_0x8ff1('0xf'),error);ami[_0x8ff1('0x1a')](_0x8ff1('0x21'),close);module[_0x8ff1('0x22')]=ami;