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
82
index.js
82
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;
|
||||||
|
@ -113,23 +113,36 @@ try {
|
||||||
// setup friends list
|
// setup friends list
|
||||||
const friends = Object.keys(config.friends);
|
const friends = Object.keys(config.friends);
|
||||||
|
|
||||||
xmpp.on('online', function(data, to) {
|
xmpp.on('online', function (data, to) {
|
||||||
// once we're online, we'll send a message alerting xmpp admins
|
// once we're online, we'll send a message alerting xmpp admins
|
||||||
console.log('Connected with JID: ' + bot_jid);
|
console.log('Connected with JID: ' + bot_jid);
|
||||||
xmpp.send(user_jid, "[ONLINE]", false);
|
xmpp.send(user_jid, "[ONLINE]", false);
|
||||||
// send mqtt online message
|
// send mqtt online message
|
||||||
client.publish(mqtt_topic, mqtt_message);
|
client.publish(mqtt_topic, mqtt_message);
|
||||||
// toot online message
|
// toot online message
|
||||||
/*
|
/*
|
||||||
M.post('statuses', {
|
M.post('statuses', {
|
||||||
status: `${mastodon_toot}`
|
status: `${mastodon_toot}`
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
});
|
});
|
||||||
// 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,7 +150,8 @@ 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');
|
||||||
xmpp.send(from, 'Invalid credentials');
|
xmpp.send(from, 'Invalid credentials');
|
||||||
|
@ -186,8 +200,9 @@ 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);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -222,7 +237,7 @@ try {
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -253,7 +268,7 @@ try {
|
||||||
console.log("Tuya API: Unknown reply!");
|
console.log("Tuya API: Unknown reply!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -270,7 +285,7 @@ try {
|
||||||
if (!error && res.statusCode == 200) {
|
if (!error && res.statusCode == 200) {
|
||||||
xmpp.send(from, 'Refreshing Tuya API auth keys');
|
xmpp.send(from, 'Refreshing Tuya API auth keys');
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -289,7 +304,7 @@ try {
|
||||||
xmpp.send(from, stat);
|
xmpp.send(from, stat);
|
||||||
console.log(stat);
|
console.log(stat);
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -307,7 +322,7 @@ try {
|
||||||
xmpp.send(from, stat);
|
xmpp.send(from, stat);
|
||||||
console.log(stat);
|
console.log(stat);
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
@ -326,7 +341,7 @@ try {
|
||||||
if (!error && res.statusCode == 200) {
|
if (!error && res.statusCode == 200) {
|
||||||
xmpp.send(from, tuya_name + " set to " + per + "%");
|
xmpp.send(from, tuya_name + " set to " + per + "%");
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
if (config.debug === '1') {
|
if (config.debug === '1') {
|
||||||
console.log('lights turned to ' + per + "%");
|
console.log('lights turned to ' + per + "%");
|
||||||
|
@ -354,7 +369,7 @@ try {
|
||||||
xmpp.send(from, tuya_name + "set to " + color);
|
xmpp.send(from, tuya_name + "set to " + color);
|
||||||
console.log(tuya_name + "set to " + color);
|
console.log(tuya_name + "set to " + color);
|
||||||
}
|
}
|
||||||
resError(error,res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
if (config.debug === '1') {
|
if (config.debug === '1') {
|
||||||
console.log(tuya_name + "set to " + color);
|
console.log(tuya_name + "set to " + color);
|
||||||
|
@ -370,20 +385,14 @@ try {
|
||||||
// send mqtt ping message
|
// send mqtt ping message
|
||||||
client.publish(mqtt_topic, from + ' has pinged you!');
|
client.publish(mqtt_topic, from + ' has pinged you!');
|
||||||
// set gotify ping message to admin
|
// set gotify ping message to admin
|
||||||
request.post(gotifyEUrl, function(err, response, body) {
|
request.post(gotifyEUrl, function (err, response, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('error:', err);
|
console.log('error:', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +402,7 @@ try {
|
||||||
xmpp.send(from, pc);
|
xmpp.send(from, pc);
|
||||||
} else {
|
} else {
|
||||||
// check current weather
|
// check current weather
|
||||||
request(weather_url, function(err, response, body) {
|
request(weather_url, function (err, response, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('error:', err);
|
console.log('error:', err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -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);
|
||||||
|
@ -472,7 +472,7 @@ try {
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
// send request to create room
|
// send request to create room
|
||||||
request(createRoom, function(error, response, body) {
|
request(createRoom, function (error, response, body) {
|
||||||
if (error) throw new Error(error);
|
if (error) throw new Error(error);
|
||||||
console.log(body);
|
console.log(body);
|
||||||
});
|
});
|
||||||
|
@ -515,11 +515,11 @@ try {
|
||||||
},
|
},
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
request(addMember, function(error, response, body) {
|
request(addMember, function (error, response, body) {
|
||||||
if (error) throw new Error(error);
|
if (error) throw new Error(error);
|
||||||
console.log(body);
|
console.log(body);
|
||||||
});
|
});
|
||||||
request(inviteMember, function(error, response, body) {
|
request(inviteMember, function (error, response, body) {
|
||||||
if (error) throw new Error(error);
|
if (error) throw new Error(error);
|
||||||
console.log(body);
|
console.log(body);
|
||||||
});
|
});
|
||||||
|
@ -549,7 +549,7 @@ try {
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
// send room delete request
|
// send room delete request
|
||||||
request(endMeeting, function(error, response, body) {
|
request(endMeeting, function (error, response, body) {
|
||||||
if (error) throw new Error(error);
|
if (error) throw new Error(error);
|
||||||
console.log(body);
|
console.log(body);
|
||||||
});
|
});
|
||||||
|
@ -581,7 +581,7 @@ try {
|
||||||
xmpp.send(from, pc);
|
xmpp.send(from, pc);
|
||||||
} else {
|
} else {
|
||||||
// get user_jid vcard (profile info)
|
// get user_jid vcard (profile info)
|
||||||
xmpp.getVCard(from, function(vcard) {
|
xmpp.getVCard(from, function (vcard) {
|
||||||
xmpp.send(from, vcard);
|
xmpp.send(from, vcard);
|
||||||
console.log(vcard)
|
console.log(vcard)
|
||||||
})
|
})
|
||||||
|
@ -596,7 +596,7 @@ try {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Catch and log XMPP errors
|
// Catch and log XMPP errors
|
||||||
xmpp.on('error', function(err) {
|
xmpp.on('error', function (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -611,7 +611,7 @@ try {
|
||||||
port: bot_port
|
port: bot_port
|
||||||
});
|
});
|
||||||
// subscribe to friends
|
// subscribe to friends
|
||||||
xmpp.on('subscribe', function(from) {
|
xmpp.on('subscribe', function (from) {
|
||||||
if (from in config.friends == true) {
|
if (from in config.friends == true) {
|
||||||
console.log('accepting subsciption request from ' + from);
|
console.log('accepting subsciption request from ' + from);
|
||||||
// accept pending subscription requests
|
// accept pending subscription requests
|
||||||
|
|
Reference in New Issue
Block a user