Built motion from commit (unavailable).|2.5.31
[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 _0x34e5=['bluebird','util','lodash','../../config/logger','ami','../../config/environment','asterisk','port','username','keepConnected','action','error','format','inspect','actionSipShowRegistry','Action','sipshowregistry','actionDeviceStateList','actionSipPeerStatus','sippeerstatus','actionQueueSummary','queuesummary','actionCoreShowChannels','info','Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s','once','close','Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s','Fullybooted\x20\x22%s\x22\x20to\x20%s:%s','then','catch','exports'];(function(_0x1ea708,_0x149b50){var _0x220803=function(_0x1b85aa){while(--_0x1b85aa){_0x1ea708['push'](_0x1ea708['shift']());}};_0x220803(++_0x149b50);}(_0x34e5,0x160));var _0x534e=function(_0x5756fc,_0x4e95c7){_0x5756fc=_0x5756fc-0x0;var _0x170244=_0x34e5[_0x5756fc];return _0x170244;};'use strict';var Manager=require('asterisk-manager');var BPromise=require(_0x534e('0x0'));var moment=require('moment');var util=require(_0x534e('0x1'));var _=require(_0x534e('0x2'));var logger=require(_0x534e('0x3'))(_0x534e('0x4'));var config=require(_0x534e('0x5'));var ami=new Manager(config[_0x534e('0x6')][_0x534e('0x7')],config[_0x534e('0x6')]['ip'],config[_0x534e('0x6')][_0x534e('0x8')],config[_0x534e('0x6')]['password'],!![]);ami[_0x534e('0x9')]();ami['Action']=BPromise['promisify'](ami[_0x534e('0xa')]);function error(_0x4a211f){logger[_0x534e('0xb')](util[_0x534e('0xc')]('Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s',config['asterisk']['username'],config['asterisk']['ip'],config['asterisk']['port'],util[_0x534e('0xd')](_0x4a211f,![],null)));}function close(){logger['error'](util['format']('Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s',config[_0x534e('0x6')]['username'],config[_0x534e('0x6')]['ip'],config[_0x534e('0x6')][_0x534e('0x7')]));}ami[_0x534e('0xe')]=function(){return function(){return ami[_0x534e('0xf')]({'action':_0x534e('0x10')});};};ami[_0x534e('0x11')]=function(){return function(){return ami[_0x534e('0xf')]({'action':'devicestatelist'});};};ami[_0x534e('0x12')]=function(){return function(){return ami[_0x534e('0xf')]({'action':_0x534e('0x13')});};};ami[_0x534e('0x14')]=function(){return function(){return ami[_0x534e('0xf')]({'action':_0x534e('0x15')});};};ami[_0x534e('0x16')]=function(){return function(){return ami[_0x534e('0xf')]({'action':'coreshowchannels'});};};function connect(_0x271acd){logger[_0x534e('0x17')](util[_0x534e('0xc')](_0x534e('0x18'),config[_0x534e('0x6')][_0x534e('0x8')],config[_0x534e('0x6')]['ip'],config['asterisk'][_0x534e('0x7')]));ami[_0x534e('0x19')](_0x534e('0xb'),error);ami['once'](_0x534e('0x1a'),close);}ami['on']('connect',connect);ami['on']('shutdown',function(_0x2eba73){logger[_0x534e('0x17')](util[_0x534e('0xc')](_0x534e('0x1b'),config[_0x534e('0x6')][_0x534e('0x8')],config['asterisk']['ip'],config[_0x534e('0x6')]['port'],util[_0x534e('0xd')](_0x2eba73,![],null)));});ami['on']('fullybooted',function(_0x64efc0){logger[_0x534e('0x17')](util['format'](_0x534e('0x1c'),config[_0x534e('0x6')]['username'],config[_0x534e('0x6')]['ip'],config[_0x534e('0x6')][_0x534e('0x7')]));return BPromise['resolve']()[_0x534e('0x1d')](ami['actionSipShowRegistry']())[_0x534e('0x1d')](ami['actionDeviceStateList']())[_0x534e('0x1d')](ami[_0x534e('0x12')]())[_0x534e('0x1d')](ami[_0x534e('0x14')]())['then'](ami['actionCoreShowChannels']())[_0x534e('0x1e')](function(_0x4fa57d){console['log'](_0x4fa57d);});});ami[_0x534e('0x19')](_0x534e('0xb'),error);ami[_0x534e('0x19')](_0x534e('0x1a'),close);module[_0x534e('0x1f')]=ami;