forked from vxmppb/vxmppb
changed constant for config.calls
function for calls (see #24) re-beautified code
This commit is contained in:
parent
4f8d74c7e3
commit
2462dce4f8
38
index.js
38
index.js
|
@ -17,7 +17,7 @@ try {
|
||||||
// check if user debugging is enabled
|
// check if user debugging is enabled
|
||||||
const debugging = config.debug;
|
const debugging = config.debug;
|
||||||
// check if user wants phone calls with commands are run
|
// check if user wants phone calls with commands are run
|
||||||
const callme = config.calls;
|
const calls_enabled = config.calls;
|
||||||
|
|
||||||
// Asterisk config
|
// Asterisk config
|
||||||
const asterisk_callfrom = config.asterisk.callfrom;
|
const asterisk_callfrom = config.asterisk.callfrom;
|
||||||
|
@ -130,6 +130,19 @@ try {
|
||||||
// wait for incoming messages
|
// wait for incoming messages
|
||||||
xmpp.on('chat', function (from, message) {
|
xmpp.on('chat', function (from, message) {
|
||||||
// check for debugging
|
// check for debugging
|
||||||
|
function call(call_data) {
|
||||||
|
if (calls_enabled === '1') {
|
||||||
|
ami.action({
|
||||||
|
'action': 'originate',
|
||||||
|
'channel': 'SIP/' + asterisk_callfrom,
|
||||||
|
'context': asterisk_context,
|
||||||
|
'callerID': asterisk_callerID,
|
||||||
|
'data': 'googletts.agi,' + call_data,
|
||||||
|
'application': 'agi'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
if (debugging === '1') {
|
if (debugging === '1') {
|
||||||
console.log('[DEBUG]');
|
console.log('[DEBUG]');
|
||||||
|
@ -137,6 +150,7 @@ try {
|
||||||
console.log(from);
|
console.log(from);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resError(error, res) {
|
function resError(error, res) {
|
||||||
if (!error && res.statusCode == 401) {
|
if (!error && res.statusCode == 401) {
|
||||||
console.log('Invalid credentials');
|
console.log('Invalid credentials');
|
||||||
|
@ -186,6 +200,7 @@ try {
|
||||||
var unlockBodyMatch = body.match(unlockBody);
|
var unlockBodyMatch = body.match(unlockBody);
|
||||||
const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n;
|
const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n;
|
||||||
xmpp.send(from, unlockFinalMessage);
|
xmpp.send(from, unlockFinalMessage);
|
||||||
|
call(unlockFinalMessage);
|
||||||
}
|
}
|
||||||
resError(error, res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
|
@ -376,14 +391,8 @@ try {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// call admin alerting of authors ping
|
// call admin alerting of authors ping
|
||||||
ami.action({
|
call_data = "hello. " + from + " has pinged you!"
|
||||||
'action': 'originate',
|
call(call_data);
|
||||||
'channel': 'SIP/' + asterisk_callfrom,
|
|
||||||
'context': asterisk_context,
|
|
||||||
'callerID': asterisk_callerID,
|
|
||||||
'data': 'googletts.agi, \"hello. ' + from + ' has pinged you!\"',
|
|
||||||
'application': 'agi'
|
|
||||||
});
|
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,15 +418,7 @@ try {
|
||||||
// send weather to xmpp admin
|
// send weather to xmpp admin
|
||||||
xmpp.send(from, wm);
|
xmpp.send(from, wm);
|
||||||
// call admin with latest weather report
|
// call admin with latest weather report
|
||||||
ami.action({
|
call(wm);
|
||||||
'action':'originate',
|
|
||||||
'channel':'SIP/' + asterisk_callfrom,
|
|
||||||
'context': asterisk_context,
|
|
||||||
'callerID' : asterisk_callerID,
|
|
||||||
'data': 'googletts.agi,' + wm,
|
|
||||||
'application': 'agi'
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
|
@ -436,7 +437,6 @@ try {
|
||||||
// secion from config.ini
|
// secion from config.ini
|
||||||
// Please note this section requires you to have an Ejabberd server.
|
// Please note this section requires you to have an Ejabberd server.
|
||||||
// I am welcome to pull requests for other servers (maybe set type in config.ini)
|
// I am welcome to pull requests for other servers (maybe set type in config.ini)
|
||||||
|
|
||||||
else if (message === '!meet') {
|
else if (message === '!meet') {
|
||||||
if (from != user_jid) {
|
if (from != user_jid) {
|
||||||
xmpp.send(from, pc);
|
xmpp.send(from, pc);
|
||||||
|
|
Reference in New Issue
Block a user