I made an implementation of Javascript Promises and I would like you to give me feedback on how I did it. I think I'm not doing it correctly in terms of chainning, also because in the code I have several levels of indentation. They almost look like Callbacks
var voladura = ctx.match[0].toUpperCase();
playground.getTelegramFileId(voladura)
.then(volObj=>{
ctx.replyWithChatAction('upload_photo');
ctx.replyWithPhoto(volObj.file_id,{
caption: 'Pozos planeados: ${volObj.pozos_planeados}\n'
})
.then(results => {
console.log('Voladura ${voladura} enviada')
});
})
.catch(err =>{
generateCanvas.createImageXLSXPro(voladura)
.then((pozosObj)=> {
ctx.replyWithChatAction('typing');
ctx.replyWithPhoto({ source: fs.readFileSync('./images/${voladura}.png')},{
caption: '⚫️ Pozos planeados: ${pozosObj.plan}'
})
.then((result) => {
console.log(voladura);
playground.saveTelegramFileId(voladura, pozosObj, result)
.then(result => {
console.log(result);
});
fs.exists('./images/${voladura}.png',(exists)=>{
if (exists) {
fs.unlinkSync('./images/${voladura}.png');
} else {
console.log('No se encontro la imagen ${voladura}.png')
}
});
})
.catch((err) => {
console.log(err);
});
})
.catch(err => {
console.log(err);
ctx.reply('No se encontraron datos de la voladura ${voladura}.