implements devices not found

This commit is contained in:
Francesco Esposito 2019-02-22 10:05:24 +01:00
parent c7cc900a9a
commit e7d52c8168
1 changed files with 30 additions and 11 deletions

View File

@ -34,11 +34,21 @@ bot.on('/list', (msg) => {
} }
api.getDevices() api.getDevices()
.then(res => res.json()) .then((res) => {
console.log(res.status);
if (res.status === 200) {
return res.json();
}
return null;
})
.then((json) => { .then((json) => {
json.forEach((elem) => { if (json) {
bot.sendMessage(msg.from.id, utils.templateDevicesList(elem), { parseMode: 'Markdown' }); json.forEach((elem) => {
}); bot.sendMessage(msg.from.id, utils.templateDevicesList(elem), { parseMode: 'Markdown' });
});
} else {
bot.sendMessage(msg.from.id, utils.templateDeviceNotFound());
}
}) })
.catch((err) => { .catch((err) => {
bot.sendMessage(msg.from.id, utils.templateError()); bot.sendMessage(msg.from.id, utils.templateError());
@ -52,15 +62,24 @@ bot.on('/position', (msg) => {
} }
api.getDevices() api.getDevices()
.then(res => res.json()) .then((res) => {
console.log(res.status);
if (res.status === 200) {
return res.json();
}
return null;
})
.then((devicesJSON) => { .then((devicesJSON) => {
const devices = []; if (devicesJSON) {
devicesJSON.forEach((device) => { const devices = [];
devices.push(device.name); devicesJSON.forEach((device) => {
}); devices.push(device.name);
});
const replyMarkup = bot.keyboard([devices], { resize: true, once: true });
return bot.sendMessage(msg.from.id, 'Select device', { ask: 'devicePosition', replyMarkup });
}
const replyMarkup = bot.keyboard([devices], { resize: true, once: true }); return bot.sendMessage(msg.from.id, utils.templateDeviceNotFound());
bot.sendMessage(msg.from.id, 'Select device', { ask: 'devicePosition', replyMarkup });
}) })
.catch((err) => { .catch((err) => {
bot.sendMessage(msg.from.id, utils.templateError()); bot.sendMessage(msg.from.id, utils.templateError());