|
|
@ -3,8 +3,6 @@ const ini = require('ini');
|
|
|
|
const mastodon = require('mastodon');
|
|
|
|
const mastodon = require('mastodon');
|
|
|
|
const mqtt = require('mqtt');
|
|
|
|
const mqtt = require('mqtt');
|
|
|
|
const request = require('request');
|
|
|
|
const request = require('request');
|
|
|
|
let Parser = require('rss-parser');
|
|
|
|
|
|
|
|
let parser = new Parser();
|
|
|
|
|
|
|
|
const xmpp = require('simple-xmpp');
|
|
|
|
const xmpp = require('simple-xmpp');
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -42,11 +40,11 @@ const mqtt_password = config.mqtt_password;
|
|
|
|
const mqtt_server = config.mqtt_server;
|
|
|
|
const mqtt_server = config.mqtt_server;
|
|
|
|
const mqtt_topic = config.mqtt_topic;
|
|
|
|
const mqtt_topic = config.mqtt_topic;
|
|
|
|
const mqtt_user = config.mqtt_user;
|
|
|
|
const mqtt_user = config.mqtt_user;
|
|
|
|
const rpc_url = config.rpc_url;
|
|
|
|
const tuya_name = config.tuya_name;
|
|
|
|
const rss_url = config.rss_url;
|
|
|
|
const tuya_status_url = config.tuya_status_url;
|
|
|
|
|
|
|
|
const tuya_toggle_url = config.tuya_toggle_url;
|
|
|
|
const user_jid = config.user_jid;
|
|
|
|
const user_jid = config.user_jid;
|
|
|
|
const user_name = config.user_name;
|
|
|
|
const user_name = config.user_name;
|
|
|
|
const vfc_url = config.vfc_url;
|
|
|
|
|
|
|
|
const weather_api_key = config.weather_api_key;
|
|
|
|
const weather_api_key = config.weather_api_key;
|
|
|
|
const weather_units = config.weather_units;
|
|
|
|
const weather_units = config.weather_units;
|
|
|
|
|
|
|
|
|
|
|
@ -121,42 +119,93 @@ xmpp.on('chat', function(from, message) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log('unlocks');
|
|
|
|
console.log('unlocks');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tuya light control
|
|
|
|
|
|
|
|
else if (message === 'lights' || message === 'Lights') {
|
|
|
|
|
|
|
|
request(tuya_status_url,(error, res, body) => {
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return console.log(error)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Check VFC balance
|
|
|
|
if (!error && res.statusCode == 200) {
|
|
|
|
else if (message === "vfc" || message === "Vfc") {
|
|
|
|
if (res.body === "true"){
|
|
|
|
ami.action({
|
|
|
|
const stat = tuya_name + ": On";
|
|
|
|
'action':'originate',
|
|
|
|
xmpp.send(from, stat);
|
|
|
|
'channel':'SIP/' + asterisk_callfrom,
|
|
|
|
console.log(stat);
|
|
|
|
'context': asterisk_context,
|
|
|
|
} else if (res.body === "false") {
|
|
|
|
'callerID' : asterisk_callerID,
|
|
|
|
const stat = tuya_name + ": Off";
|
|
|
|
'exten' : asterisk_callto,
|
|
|
|
xmpp.send(from, stat);
|
|
|
|
'priority' : '1',
|
|
|
|
console.log(stat);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
request(vfc_url, (error, res, body) => {
|
|
|
|
xmpp.send(from, "Unknown reply. Please reply ping to reach an admin.");
|
|
|
|
if (error) {
|
|
|
|
console.log("Tuya API: Unknown reply!");
|
|
|
|
return console.log(error)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 200) {
|
|
|
|
|
|
|
|
const balance = user_name + " has " + res.body + " VFC";
|
|
|
|
|
|
|
|
xmpp.send(from, balance);
|
|
|
|
|
|
|
|
console.log(balance);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log('vfc');
|
|
|
|
if (!error && res.statusCode == 401) {
|
|
|
|
|
|
|
|
console.log('Invalid credentials');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Invalid credentials');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 404) {
|
|
|
|
|
|
|
|
console.log('Record not found');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Record not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 500) {
|
|
|
|
|
|
|
|
console.log('Server error.');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Server error. Please ping admin');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('lights status');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (message === tuya_name + ' on') {
|
|
|
|
|
|
|
|
request(tuya_toggle_url + "?stat=true&devname=" + tuya_name,(error, res, body) => {
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return console.log(error)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Get latest RSS item from feed
|
|
|
|
if (!error && res.statusCode == 200) {
|
|
|
|
else if (message === "rss" || message === "Rss") {
|
|
|
|
const stat = tuya_name + " has been turned on";
|
|
|
|
(async () => {
|
|
|
|
xmpp.send(from, stat);
|
|
|
|
let feed = await parser.parseURL(rss_url);
|
|
|
|
console.log(stat);
|
|
|
|
// console.log(feed.title);
|
|
|
|
}
|
|
|
|
feed.items.forEach(item => {
|
|
|
|
if (!error && res.statusCode == 401) {
|
|
|
|
console.log(item.title + ':' + item.link)
|
|
|
|
console.log('Invalid credentials');
|
|
|
|
xmpp.send(from, item.title)
|
|
|
|
xmpp.send(from, 'Invalid credentials');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
xmpp.send(from, 'See https://vanderwarker.social/@stephen for full entries.')
|
|
|
|
if (!error && res.statusCode == 404) {
|
|
|
|
})();
|
|
|
|
console.log('Record not found');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Record not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 500) {
|
|
|
|
|
|
|
|
console.log('Server error.');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Server error. Please ping admin');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('lights on');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (message === tuya_name + ' off') {
|
|
|
|
|
|
|
|
request(tuya_toggle_url + "?stat=false&devname=" + tuya_name,(error, res, body) => {
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return console.log(error)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 200) {
|
|
|
|
|
|
|
|
const stat = tuya_name + " has been turned off";
|
|
|
|
|
|
|
|
xmpp.send(from, stat);
|
|
|
|
|
|
|
|
console.log(stat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 401) {
|
|
|
|
|
|
|
|
console.log('Invalid credentials');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Invalid credentials');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 404) {
|
|
|
|
|
|
|
|
console.log('Record not found');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Record not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error && res.statusCode == 500) {
|
|
|
|
|
|
|
|
console.log('Server error.');
|
|
|
|
|
|
|
|
xmpp.send(from, 'Server error. Please ping admin');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('lights on');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ping a user to let them know you would like to communitcate
|
|
|
|
// Ping a user to let them know you would like to communitcate
|
|
|
@ -236,10 +285,11 @@ xmpp.on('chat', function(from, message) {
|
|
|
|
console.log(vcard)
|
|
|
|
console.log(vcard)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the user sends something we don't have logic for, send them info about the project
|
|
|
|
// If the user sends something we don't have logic for, send them info about the project
|
|
|
|
else { xmpp.send(from, "This is an auto replying bot. Reply \"help\" for more info, or https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:start");
|
|
|
|
else {
|
|
|
|
console.log('autoreply');
|
|
|
|
xmpp.send(from, "This is an auto replying bot. Reply \"help\" for more info, or https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:start");
|
|
|
|
|
|
|
|
console.log('autoreply');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -248,16 +298,8 @@ xmpp.on('error', function(err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// EXTENDING XEPS (WIP)
|
|
|
|
// Set XMPP status
|
|
|
|
/*
|
|
|
|
xmpp.setPresence('chat', 'Asterisk,Mastodon, and MQTT. Oh my!');
|
|
|
|
xmpp.on('chatstate', function(from, state) {
|
|
|
|
|
|
|
|
console.log(state);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmpp.on('buddy', function(jid, state, statusText, resource) {
|
|
|
|
|
|
|
|
console.log(state + statusText + resource);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Alas, we connect to XMPP!
|
|
|
|
// Alas, we connect to XMPP!
|
|
|
|
xmpp.connect({
|
|
|
|
xmpp.connect({
|
|
|
|