2019-02-19 14:47:31 +01:00
|
|
|
|
const config = require('./config');
|
|
|
|
|
|
2019-02-21 14:54:46 +01:00
|
|
|
|
function convertTimestamp(timestamp) {
|
|
|
|
|
return new Date(timestamp * 1000).toISOString().slice(0, 19);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 14:47:31 +01:00
|
|
|
|
// template
|
|
|
|
|
function templateStart() {
|
|
|
|
|
const msg = `* Welcome to ${config.app.name} 📱📡*\n
|
|
|
|
|
A bot to track your devices with GPS.
|
|
|
|
|
|
|
|
|
|
Please, read the README on
|
|
|
|
|
https://github.com/frab1t/trackmyd-bot
|
|
|
|
|
to configure the bot.
|
|
|
|
|
|
|
|
|
|
Made with ❤️ by @frab1t`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateHelp() {
|
|
|
|
|
const msg = `📃 * ${config.app.name} commands*: \n
|
|
|
|
|
/help - view commands.
|
|
|
|
|
/position - view device's position.
|
|
|
|
|
/list - view device available.
|
|
|
|
|
/add - add new device.
|
|
|
|
|
/remove - remove device.`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateUnauthorizedUser() {
|
|
|
|
|
const msg = `Unauthorized user. 🤖 \n
|
2019-02-19 14:56:38 +01:00
|
|
|
|
Clone the repository https://github.com/frab1t/trackmyd-bot
|
2019-02-19 14:47:31 +01:00
|
|
|
|
and run the bot on your local network. 😎`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 17:46:21 +01:00
|
|
|
|
function templatePosition(data) {
|
2019-02-21 12:58:28 +01:00
|
|
|
|
const msg = `📲 📡 *${data.name}*
|
|
|
|
|
|
2019-02-21 14:54:46 +01:00
|
|
|
|
🏔️ _Altitude_: *${Math.trunc(data.position.altitude)} m*
|
|
|
|
|
⚡️ _Speed_: *${data.position.speed} m/s*
|
|
|
|
|
📏 _Accurancy_: *${Math.trunc(data.position.accurancy)} m*
|
2019-02-21 12:58:28 +01:00
|
|
|
|
🔋 _Battery_: *${data.information.battery}%*
|
|
|
|
|
|
2019-02-21 14:54:46 +01:00
|
|
|
|
_Last Update_: ${convertTimestamp(data.lastUpdate)}`;
|
2019-02-20 17:46:21 +01:00
|
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateDevicesList(data) {
|
2019-02-21 12:58:28 +01:00
|
|
|
|
const msg = `📲 *${data.name}*
|
|
|
|
|
----
|
2019-02-20 17:46:21 +01:00
|
|
|
|
${data._id}`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 13:05:33 +01:00
|
|
|
|
function templateError(data) {
|
|
|
|
|
const msg = 'Error, check the server.log';
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 14:54:46 +01:00
|
|
|
|
function templateDeviceNotFound(data) {
|
|
|
|
|
const msg = `Device _"${data}"_ not found`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateAddDeviceURL(data) {
|
|
|
|
|
const msg = `${config.api.baseURL}${config.api.paths.devices}${data._id}`;
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateAddDeviceHeader() {
|
|
|
|
|
const msg = JSON.stringify(config.api.headers);
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function templateAddDeviceBody() {
|
|
|
|
|
const msg = `{
|
|
|
|
|
"position": {
|
|
|
|
|
"latitude": %LAT,
|
|
|
|
|
"longtitude": %LON,
|
|
|
|
|
"altitude": %ALT,
|
|
|
|
|
"speed": %SPD,
|
|
|
|
|
"accurancy": %ACC
|
|
|
|
|
},
|
|
|
|
|
"information": {
|
|
|
|
|
"battery": %BATT
|
|
|
|
|
},
|
|
|
|
|
"lastUpdate": %TIMESTAMP
|
|
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 14:47:31 +01:00
|
|
|
|
module.exports.templateStart = templateStart;
|
|
|
|
|
module.exports.templateHelp = templateHelp;
|
|
|
|
|
module.exports.templateUnauthorizedUser = templateUnauthorizedUser;
|
2019-02-20 17:46:21 +01:00
|
|
|
|
module.exports.templatePosition = templatePosition;
|
|
|
|
|
module.exports.templateDevicesList = templateDevicesList;
|
2019-02-21 13:05:33 +01:00
|
|
|
|
module.exports.templateError = templateError;
|
2019-02-21 14:54:46 +01:00
|
|
|
|
module.exports.templateDeviceNotFound = templateDeviceNotFound;
|
|
|
|
|
module.exports.templateAddDeviceURL = templateAddDeviceURL;
|
|
|
|
|
module.exports.templateAddDeviceHeader = templateAddDeviceHeader;
|
|
|
|
|
module.exports.templateAddDeviceBody = templateAddDeviceBody;
|