fix: add parsing income message

This commit is contained in:
2024-05-16 23:03:09 +03:00
parent dd4d14c100
commit 4cc2b8d098
2 changed files with 54 additions and 8 deletions

View File

@@ -48,7 +48,7 @@ var simpleParser = require('mailparser').simpleParser;
var Telegraf = require('telegraf').Telegraf;
require('dotenv').config();
var bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN);
var POLLING_TIMEOUT = 30;
var POLLING_TIMEOUT = process.env.POLLING_TIMEOUT;
var MARK_STRING = process.env.MARK_STRING;
var clientConfig = {
host: process.env.EMAIL_IMAP_SERVER,
@@ -90,7 +90,7 @@ var main = function () { return __awaiter(_this, void 0, void 0, function () {
_f = _c.value;
_a = false;
message = _f;
if (!(message.envelope.subject === MARK_STRING)) return [3 /*break*/, 2];
if (!message.envelope.subject.includes(MARK_STRING)) return [3 /*break*/, 2];
email = Buffer.from(message.source).toString();
return [4 /*yield*/, simpleParser(email)];
case 1:
@@ -103,7 +103,7 @@ var main = function () { return __awaiter(_this, void 0, void 0, function () {
}
client.messageFlagsAdd(message.seq.toString(), ['\\Seen'])
.then(function (result) { return console.log('📌', chalk.cyan("Set seen flag for id-".concat(message.seq)), result); })
.catch(function (error) { return console.log(error); });
.catch(console.error);
_h.label = 2;
case 2: return [2 /*return*/];
}
@@ -160,7 +160,7 @@ var main = function () { return __awaiter(_this, void 0, void 0, function () {
//main().then().catch(err => console.error(err)); // start once for development
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
main().then().catch(function (err) { return console.error(err); });
main().then().catch(console.error);
return [2 /*return*/];
});
}); }, POLLING_TIMEOUT * 1000);
}); }, Number(POLLING_TIMEOUT) * 1000);