mirror of
https://github.com/franjsco/trackmyd-bot
synced 2025-06-05 22:19:29 +02:00
implements devices not found
This commit is contained in:
27
server.js
27
server.js
@@ -34,11 +34,21 @@ bot.on('/list', (msg) => {
|
||||
}
|
||||
|
||||
api.getDevices()
|
||||
.then(res => res.json())
|
||||
.then((res) => {
|
||||
console.log(res.status);
|
||||
if (res.status === 200) {
|
||||
return res.json();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.then((json) => {
|
||||
if (json) {
|
||||
json.forEach((elem) => {
|
||||
bot.sendMessage(msg.from.id, utils.templateDevicesList(elem), { parseMode: 'Markdown' });
|
||||
});
|
||||
} else {
|
||||
bot.sendMessage(msg.from.id, utils.templateDeviceNotFound());
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
bot.sendMessage(msg.from.id, utils.templateError());
|
||||
@@ -52,15 +62,24 @@ bot.on('/position', (msg) => {
|
||||
}
|
||||
|
||||
api.getDevices()
|
||||
.then(res => res.json())
|
||||
.then((res) => {
|
||||
console.log(res.status);
|
||||
if (res.status === 200) {
|
||||
return res.json();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.then((devicesJSON) => {
|
||||
if (devicesJSON) {
|
||||
const devices = [];
|
||||
devicesJSON.forEach((device) => {
|
||||
devices.push(device.name);
|
||||
});
|
||||
|
||||
const replyMarkup = bot.keyboard([devices], { resize: true, once: true });
|
||||
bot.sendMessage(msg.from.id, 'Select device', { ask: 'devicePosition', replyMarkup });
|
||||
return bot.sendMessage(msg.from.id, 'Select device', { ask: 'devicePosition', replyMarkup });
|
||||
}
|
||||
|
||||
return bot.sendMessage(msg.from.id, utils.templateDeviceNotFound());
|
||||
})
|
||||
.catch((err) => {
|
||||
bot.sendMessage(msg.from.id, utils.templateError());
|
||||
|
Reference in New Issue
Block a user