a47295fd3fceed7bcca868f99fb0f8b4511282ef
[motion.git] / server / config / autodialer / index.js
1 'use strict';
2 var util = require('util');
3 var Process = require('./process');
4
5 module.exports = function(ami) {
6
7   console.log('Autodialer Starting...');
8   var proc = new Process();
9
10   proc.getProcesses(function(res, err) {
11     if(err)
12     {
13       console.log(err);
14       return;
15     }
16     // console.log(res.Contacts);
17     // if (util.isArray(res.Contacts))
18     // {
19     //   var contact = res.Contacts;
20     //   console.log(contact);
21     // }
22     // else
23     // {
24     //   var contacts = res.Contacts;
25     //   if (contacts.length)
26     //   {
27     //     contacts.forEach(function(contact) {
28     //       console.log(contact);
29     //     })
30     //   }
31     // }
32
33
34
35   });
36
37 }
38
39 // var _ = require('lodash');
40 //
41 // var agents = ['SIP/massimiliano.bungaro', 'SIP/daniele.cinti'];
42 // var channels = [];
43 // var peers = [];
44 // var contacts = ['600', '600', '600'];
45 //
46 // var ami;
47 //
48 // function coreshow() {
49 //   channels = [];
50 //   if (contacts.length > 0) {
51 //     ami.action({
52 //       action: 'CoreShowChannels'
53 //     }, function(err, res) {
54 //       if (err) {
55 //         console.log(err);
56 //       }
57 //       console.log(res);
58 //     });
59 //   }
60 //
61 // }
62 //
63 // function peerstatus() {
64 //   peers = [];
65 //   if (contacts.length > 0) {
66 //     ami.action({
67 //       action: 'SIPpeerstatus'
68 //     }, function(err, res) {
69 //       if (err) {
70 //         console.log(err);
71 //       }
72 //       console.log(res);
73 //     })
74 //   }
75 // }
76 //
77 // module.exports = function(asterisk_manager) {
78 //
79 //   ami = asterisk_manager;
80 //
81 //   peerstatus();
82 //
83 //   ami.on('peerstatus', function(evt) {
84 //     if (evt.peerstatus == 'Reachable') {
85 //       peers.push(evt.peer);
86 //     }
87 //   });
88 //
89 //   ami.on('coreshowchannel', function(evt) {
90 //     channels.push(evt.channel.split('-')[0]);
91 //   });
92 //
93 //   ami.on('sippeerstatuscomplete', function(evt) {
94 //     coreshow();
95 //   });
96 //
97 //   ami.on('coreshowchannelscomplete', function(evt) {
98 //     console.log('Agents registered ', peers);
99 //     console.log('Agents in call ', channels);
100 //
101 //
102 //     var agent = _.find(agents, function(agent) {
103 //       return !_.includes(channels, agent);
104 //     });
105 //
106 //     if (agent) {
107 //       if (_.includes(peers, agent)) {
108 //         ami.action({
109 //           action: 'originate',
110 //           channel: agent,
111 //           exten: contacts.pop(),
112 //           context: 'demo',
113 //           priority: 1,
114 //           async: true
115 //         }, function(err, res) {
116 //           if (err) {
117 //             console.log(err);
118 //           }
119 //           console.log(res);
120 //         });
121 //       }
122 //     }
123 //     peerstatus();
124 //   });
125 // };