import from json

This commit is contained in:
Artyom Ashirov 2024-11-15 07:07:02 +03:00
parent 4251f1a0bd
commit de5e405093
2 changed files with 6 additions and 5 deletions

View File

@ -449,8 +449,11 @@ export default class AdminProductHandler {
}
const file = await this.bot.getFile(msg.document.file_id);
const fileContent = await this.bot.downloadFile(file.file_id, '/tmp');
const fileContent = await this.bot.downloadFile(file.file_id, '.');
jsonContent = await fs.readFile(fileContent, 'utf8');
await fs.rm(fileContent);
} else if (msg.text) {
jsonContent = msg.text;
} else {
@ -503,9 +506,9 @@ export default class AdminProductHandler {
this.userStates.delete(chatId);
} catch (error) {
await db.runAsync('ROLLBACK');
console.error('Error importing products:', error);
await this.bot.sendMessage(chatId, 'Error importing products. Please check the data and try again.');
await db.runAsync('ROLLBACK');
}
return true;

View File

@ -69,9 +69,7 @@ bot.onText(/\/admin/, async (msg) => {
// Handle user menu buttons
bot.on('message', async (msg) => {
if (!msg.text) return;
if (msg.text.toLowerCase() === '/start') {
if (msg.text && msg.text.toLowerCase() === '/start') {
return;
}