@afilimax/message-text-parser 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/offer-parser.interface.d.ts +8 -0
- package/dist/interfaces/offer-parser.interface.js +2 -0
- package/dist/interfaces/parse-contex.interface.d.ts +3 -0
- package/dist/interfaces/parse-contex.interface.js +2 -0
- package/dist/interfaces/telegram-parser-meta.interface.d.ts +3 -0
- package/dist/interfaces/telegram-parser-meta.interface.js +2 -0
- package/dist/parser-engine.d.ts +8 -0
- package/dist/parser-engine.js +27 -0
- package/dist/parsers/index.d.ts +5 -0
- package/dist/parsers/index.js +21 -0
- package/dist/parsers/ofertas-adrenaline.parser.d.ts +2 -0
- package/dist/parsers/ofertas-adrenaline.parser.js +36 -0
- package/dist/parsers/pc-do-fafa.parser.d.ts +2 -0
- package/dist/parsers/pc-do-fafa.parser.js +34 -0
- package/dist/parsers/promocoes-do-tec.parser.d.ts +2 -0
- package/dist/parsers/promocoes-do-tec.parser.js +47 -0
- package/dist/parsers/skandar-souza-promocoes.parser.d.ts +2 -0
- package/dist/parsers/skandar-souza-promocoes.parser.js +37 -0
- package/dist/parsers/tj-gaming.parser.d.ts +2 -0
- package/dist/parsers/tj-gaming.parser.js +34 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +18 -0
- package/dist/schemas/offer.schema.d.ts +12 -0
- package/dist/schemas/offer.schema.js +11 -0
- package/dist/schemas/price.schema.d.ts +7 -0
- package/dist/schemas/price.schema.js +9 -0
- package/dist/utils/collapse-white-space.util.d.ts +1 -0
- package/dist/utils/collapse-white-space.util.js +8 -0
- package/dist/utils/extract-coupons.util.d.ts +1 -0
- package/dist/utils/extract-coupons.util.js +11 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/money.util.d.ts +1 -0
- package/dist/utils/money.util.js +6 -0
- package/dist/utils/remove-emojis.util.d.ts +1 -0
- package/dist/utils/remove-emojis.util.js +6 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcuth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @afilimax/message-text-parser
|
|
2
|
+
|
|
3
|
+
Esta é uma biblioteca focada em extrair dados de mensagens de ofertas enviadas por canais do Telegram brasileiros.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @afilimax/message-text-parser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Uso
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { defaultParser } from "@afilimax/message-text-parser"
|
|
15
|
+
|
|
16
|
+
const offer = defaultParser.parse(`Tênis Charged Starlight Se Under Armour
|
|
17
|
+
|
|
18
|
+
💲R$ 158,99
|
|
19
|
+
💳 Em 6x Sem Juros
|
|
20
|
+
🎟 Cupom: CARNAVAL40
|
|
21
|
+
|
|
22
|
+
🔗https://mercadolivre.com/sec/2yaVLgw`) // Offer | null
|
|
23
|
+
|
|
24
|
+
console.log(offer) /* {
|
|
25
|
+
title: 'Tênis Charged Starlight Se Under Armour',
|
|
26
|
+
price: { value: 158990, oldValue: null, currency: 'BRL' },
|
|
27
|
+
url: 'https://mercadolivre.com/sec/2yaVLgw',
|
|
28
|
+
coupons: [ 'CARNAVAL40' ]
|
|
29
|
+
} */
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Canais suportados intencionalmente
|
|
33
|
+
|
|
34
|
+
- [PC DO FAFA PROMOÇÕES](https://t.me/pcdofafapromo)
|
|
35
|
+
- [TJ Gaming](https://t.me/TJGOFERTASs)
|
|
36
|
+
- [Ofertas Adrenaline](https://t.me/ofertasadrenaline)
|
|
37
|
+
- [Iskandar Souza - Promoções](https://t.me/IskandarSouza)
|
|
38
|
+
- [Promocoes Do Tec](https://t.me/tecnoinffo)
|
|
39
|
+
|
|
40
|
+
> Pode haver suporte a outros canais pelo fato do padrão de mensagens ser o mesmo, mas não são suportados intencionalmente. Se estiver interessado em adicionar suporte a um canal, abra um issue ou envie uma pull request com um parser implementado.
|
|
41
|
+
|
|
42
|
+
## Como criar seu próprio parser e registrá-lo
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { OfferParser } from "@afilimax/message-text-parser"
|
|
46
|
+
|
|
47
|
+
const myParser: OfferParser<TelegramParserMeta> = {
|
|
48
|
+
name: "meu-parser",
|
|
49
|
+
meta: {
|
|
50
|
+
telegramChannelId: "TELEGRAM_CHAT_ID", // serve para que se você, no ato de parsing, enviar o channelId, ele vai mais facilmente identificar o parser correto por conta da condicional em `canParse`
|
|
51
|
+
},
|
|
52
|
+
canParse(text, context) {
|
|
53
|
+
if (context?.channelId && context.channelId === this.meta?.telegramChannelId) {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false
|
|
58
|
+
},
|
|
59
|
+
parse(text: string) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Depois de criar o parser, basta registrá-lo no parser principal:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { defaultParser } from "@afilimax/message-text-parser"
|
|
69
|
+
|
|
70
|
+
defaultParser.register(myParser)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Ou um parser novo:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MessageTextParser } from "@afilimax/message-text-parser"
|
|
77
|
+
|
|
78
|
+
const parser = new MessageTextParser()
|
|
79
|
+
|
|
80
|
+
parser.register(myParser)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Contribuindo
|
|
84
|
+
|
|
85
|
+
Se você quiser contribuir para o projeto, abra um issue ou envie uma pull request.
|
|
86
|
+
|
|
87
|
+
## Licença
|
|
88
|
+
|
|
89
|
+
Este projeto está licenciado sob a licença MIT - veja o arquivo [LICENSE](LICENSE) para detalhes.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageTextParser = exports.defaultParser = void 0;
|
|
4
|
+
const parsers_1 = require("./parsers");
|
|
5
|
+
const parser_engine_1 = require("./parser-engine");
|
|
6
|
+
Object.defineProperty(exports, "MessageTextParser", { enumerable: true, get: function () { return parser_engine_1.MessageTextParser; } });
|
|
7
|
+
exports.defaultParser = new parser_engine_1.MessageTextParser();
|
|
8
|
+
exports.defaultParser.register(parsers_1.pcDoFafaParser);
|
|
9
|
+
exports.defaultParser.register(parsers_1.tjGamingParser);
|
|
10
|
+
exports.defaultParser.register(parsers_1.ofertasAdrenalineParser);
|
|
11
|
+
exports.defaultParser.register(parsers_1.skandarSouzaPromocoesParser);
|
|
12
|
+
exports.defaultParser.register(parsers_1.promocoesDoTecParser);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./offer-parser.interface"), exports);
|
|
18
|
+
__exportStar(require("./parse-contex.interface"), exports);
|
|
19
|
+
__exportStar(require("./telegram-parser-meta.interface"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParseContext } from "./parse-contex.interface";
|
|
2
|
+
import { Offer } from "../schemas";
|
|
3
|
+
export interface OfferParser<T = any> {
|
|
4
|
+
name: string;
|
|
5
|
+
meta?: T;
|
|
6
|
+
canParse(text: string, context?: ParseContext): boolean;
|
|
7
|
+
parse(text: string, context?: ParseContext): Offer | null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParseContext } from "./interfaces/parse-contex.interface";
|
|
2
|
+
import { OfferParser } from "./interfaces/offer-parser.interface";
|
|
3
|
+
import { Offer } from "./schemas";
|
|
4
|
+
export declare class MessageTextParser {
|
|
5
|
+
private readonly parsers;
|
|
6
|
+
register(parser: OfferParser): void;
|
|
7
|
+
parse(text: string, context?: ParseContext): Offer | null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageTextParser = void 0;
|
|
4
|
+
const schemas_1 = require("./schemas");
|
|
5
|
+
class MessageTextParser {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.parsers = [];
|
|
8
|
+
}
|
|
9
|
+
register(parser) {
|
|
10
|
+
this.parsers.push(parser);
|
|
11
|
+
}
|
|
12
|
+
parse(text, context) {
|
|
13
|
+
for (const parser of this.parsers) {
|
|
14
|
+
if (!parser.canParse(text, context))
|
|
15
|
+
continue;
|
|
16
|
+
const result = parser.parse(text, context);
|
|
17
|
+
if (!result)
|
|
18
|
+
continue;
|
|
19
|
+
const validated = schemas_1.offerSchema.safeParse(result);
|
|
20
|
+
if (validated.success) {
|
|
21
|
+
return validated.data;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MessageTextParser = MessageTextParser;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pc-do-fafa.parser"), exports);
|
|
18
|
+
__exportStar(require("./tj-gaming.parser"), exports);
|
|
19
|
+
__exportStar(require("./skandar-souza-promocoes.parser"), exports);
|
|
20
|
+
__exportStar(require("./ofertas-adrenaline.parser"), exports);
|
|
21
|
+
__exportStar(require("./promocoes-do-tec.parser"), exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ofertasAdrenalineParser = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
exports.ofertasAdrenalineParser = {
|
|
6
|
+
name: "ofertas-adrenaline",
|
|
7
|
+
meta: {
|
|
8
|
+
telegramChannelId: "-1001501035980",
|
|
9
|
+
},
|
|
10
|
+
canParse(text, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((context === null || context === void 0 ? void 0 : context.channelId) && context.channelId === ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.telegramChannelId)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return /por\s+R\$\s*[\d.,]+/i.test(text);
|
|
16
|
+
},
|
|
17
|
+
parse(text) {
|
|
18
|
+
const titlePriceMatch = text.match(/^(.*?)\s+por\s+R\$\s*([\d.,]+)/im);
|
|
19
|
+
const urlMatch = text.match(/Compre\s+aqui:\s*(https?:\/\/[^\s]+)/i) || text.match(/https?:\/\/[^\s]+/);
|
|
20
|
+
if (!titlePriceMatch || !urlMatch)
|
|
21
|
+
return null;
|
|
22
|
+
const title = (0, utils_1.collapseWhiteSpaces)((0, utils_1.removeEmojis)(titlePriceMatch[1]));
|
|
23
|
+
const priceValue = (0, utils_1.parseBrl)(titlePriceMatch[2]);
|
|
24
|
+
const coupons = (0, utils_1.extractCoupons)(text);
|
|
25
|
+
return {
|
|
26
|
+
title: title,
|
|
27
|
+
price: {
|
|
28
|
+
value: priceValue * 1000,
|
|
29
|
+
oldValue: null,
|
|
30
|
+
currency: "BRL",
|
|
31
|
+
},
|
|
32
|
+
url: urlMatch[1] || urlMatch[0],
|
|
33
|
+
coupons: coupons,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pcDoFafaParser = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
exports.pcDoFafaParser = {
|
|
6
|
+
name: "pc-do-fafa",
|
|
7
|
+
meta: {
|
|
8
|
+
telegramChannelId: "-1001622757657",
|
|
9
|
+
},
|
|
10
|
+
canParse(text, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((context === null || context === void 0 ? void 0 : context.channelId) && context.channelId === ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.telegramChannelId)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return text.includes("💲") && text.includes("👀");
|
|
16
|
+
},
|
|
17
|
+
parse(text) {
|
|
18
|
+
const titleMatch = text.match(/^👌\s*(.*?)(?:\n|$)/m);
|
|
19
|
+
const priceMatch = text.match(/💲\s*Valor\s*:\s*R\$\s*([\d.,]+)/);
|
|
20
|
+
const urlMatch = text.match(/👀\s*(https?:\/\/[^\s]+)/);
|
|
21
|
+
if (!titleMatch || !priceMatch || !urlMatch)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
title: (0, utils_1.collapseWhiteSpaces)((0, utils_1.removeEmojis)(titleMatch[1])),
|
|
25
|
+
price: {
|
|
26
|
+
value: (0, utils_1.parseBrl)(priceMatch[1]) * 1000,
|
|
27
|
+
oldValue: null,
|
|
28
|
+
currency: "BRL",
|
|
29
|
+
},
|
|
30
|
+
url: urlMatch[1],
|
|
31
|
+
coupons: (0, utils_1.extractCoupons)(text),
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promocoesDoTecParser = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
exports.promocoesDoTecParser = {
|
|
6
|
+
name: "promocoes-do-tec",
|
|
7
|
+
meta: {
|
|
8
|
+
telegramChannelId: "-1001184851880",
|
|
9
|
+
},
|
|
10
|
+
canParse(text, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((context === null || context === void 0 ? void 0 : context.channelId) && context.channelId === ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.telegramChannelId)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (text.toLowerCase().includes("resgate aqui") &&
|
|
16
|
+
!text.includes("💲")) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
parse(text) {
|
|
22
|
+
const lines = text
|
|
23
|
+
.split("\n")
|
|
24
|
+
.map(l => l.trim())
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
if (!lines.length)
|
|
27
|
+
return null;
|
|
28
|
+
const title = lines[0]
|
|
29
|
+
.replace(/^🚨\s*/g, "")
|
|
30
|
+
.trim();
|
|
31
|
+
const priceMatch = text.match(/💲\s*R\$\s*([\d.,]+)/i);
|
|
32
|
+
const urlMatch = text.match(/https?:\/\/[^\s]+/i);
|
|
33
|
+
if (!priceMatch || !urlMatch)
|
|
34
|
+
return null;
|
|
35
|
+
const coupons = (0, utils_1.extractCoupons)(text);
|
|
36
|
+
return {
|
|
37
|
+
title: (0, utils_1.collapseWhiteSpaces)((0, utils_1.removeEmojis)(title)),
|
|
38
|
+
price: {
|
|
39
|
+
value: (0, utils_1.parseBrl)(priceMatch[1]) * 1000,
|
|
40
|
+
currency: "BRL",
|
|
41
|
+
oldValue: null,
|
|
42
|
+
},
|
|
43
|
+
url: urlMatch[0],
|
|
44
|
+
coupons: coupons,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skandarSouzaPromocoesParser = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
exports.skandarSouzaPromocoesParser = {
|
|
6
|
+
name: "skandar-souza-promocoes",
|
|
7
|
+
meta: {
|
|
8
|
+
telegramChannelId: "-1001182556721",
|
|
9
|
+
},
|
|
10
|
+
canParse(text, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((context === null || context === void 0 ? void 0 : context.channelId) && context.channelId === ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.telegramChannelId)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return /R?\$\s*[\d.,]+/.test(text) && /https?:\/\/\S+/.test(text);
|
|
16
|
+
},
|
|
17
|
+
parse(text) {
|
|
18
|
+
const titleMatch = text.match(/^(?:🔥)?\s*(.+?)(?:🔥)?\s*(?:\n|$)/m);
|
|
19
|
+
const priceMatch = text.match(/(?:💰|💸|por|Valor:)\s*(?:R\$)?\s*([\d.,]+)/i);
|
|
20
|
+
const urlMatch = text.match(/https?:\/\/[^\s]+/);
|
|
21
|
+
if (!titleMatch || !priceMatch || !urlMatch)
|
|
22
|
+
return null;
|
|
23
|
+
const title = (0, utils_1.collapseWhiteSpaces)((0, utils_1.removeEmojis)(titleMatch[1]));
|
|
24
|
+
const priceValue = (0, utils_1.parseBrl)(priceMatch[1]);
|
|
25
|
+
const coupons = (0, utils_1.extractCoupons)(text);
|
|
26
|
+
return {
|
|
27
|
+
title: title,
|
|
28
|
+
price: {
|
|
29
|
+
value: priceValue * 1000,
|
|
30
|
+
oldValue: null,
|
|
31
|
+
currency: "BRL",
|
|
32
|
+
},
|
|
33
|
+
url: urlMatch[0],
|
|
34
|
+
coupons: coupons,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tjGamingParser = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
exports.tjGamingParser = {
|
|
6
|
+
name: "tj-gaming",
|
|
7
|
+
meta: {
|
|
8
|
+
telegramChannelId: "-1001610005189",
|
|
9
|
+
},
|
|
10
|
+
canParse(text, context) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((context === null || context === void 0 ? void 0 : context.channelId) && context.channelId === ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.telegramChannelId)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return text.includes("🔥") && text.includes("💵");
|
|
16
|
+
},
|
|
17
|
+
parse(text) {
|
|
18
|
+
const titleMatch = text.match(/^🔥\s*(.*?)\s*(?:\n|$)/m);
|
|
19
|
+
const priceMatch = text.match(/💵\s*R\$?\s*([\d.,]+)/);
|
|
20
|
+
const urlMatch = text.match(/https?:\/\/[^\s]+/);
|
|
21
|
+
if (!titleMatch || !priceMatch || !urlMatch)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
title: (0, utils_1.collapseWhiteSpaces)((0, utils_1.removeEmojis)(titleMatch[1])),
|
|
25
|
+
price: {
|
|
26
|
+
value: (0, utils_1.parseBrl)(priceMatch[1]) * 1000,
|
|
27
|
+
oldValue: null,
|
|
28
|
+
currency: "BRL",
|
|
29
|
+
},
|
|
30
|
+
url: urlMatch[0],
|
|
31
|
+
coupons: (0, utils_1.extractCoupons)(text),
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./offer.schema"), exports);
|
|
18
|
+
__exportStar(require("./price.schema"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const offerSchema: z.ZodObject<{
|
|
3
|
+
title: z.ZodString;
|
|
4
|
+
price: z.ZodObject<{
|
|
5
|
+
value: z.ZodNumber;
|
|
6
|
+
oldValue: z.ZodNullable<z.ZodNumber>;
|
|
7
|
+
currency: z.ZodLiteral<"BRL">;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
url: z.ZodURL;
|
|
10
|
+
coupons: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type Offer = z.infer<typeof offerSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offerSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const price_schema_1 = require("./price.schema");
|
|
6
|
+
exports.offerSchema = zod_1.z.object({
|
|
7
|
+
title: zod_1.z.string().min(3),
|
|
8
|
+
price: price_schema_1.priceSchema,
|
|
9
|
+
url: zod_1.z.url(),
|
|
10
|
+
coupons: zod_1.z.array(zod_1.z.string()).nullable(),
|
|
11
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.priceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.priceSchema = zod_1.z.object({
|
|
6
|
+
value: zod_1.z.number().positive(),
|
|
7
|
+
oldValue: zod_1.z.number().positive().nullable(),
|
|
8
|
+
currency: zod_1.z.literal("BRL"),
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function collapseWhiteSpaces(text: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractCoupons(text: string): string[] | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCoupons = extractCoupons;
|
|
4
|
+
function extractCoupons(text) {
|
|
5
|
+
const matches = Array.from(text.matchAll(/cupom(?:\s+no\s+app)?[::]?\s*([A-Z0-9]{4,})/gi));
|
|
6
|
+
const coupons = [...new Set(matches.map((m) => m[1].toUpperCase()))];
|
|
7
|
+
if (coupons.length > 0) {
|
|
8
|
+
return coupons;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./extract-coupons.util"), exports);
|
|
18
|
+
__exportStar(require("./money.util"), exports);
|
|
19
|
+
__exportStar(require("./remove-emojis.util"), exports);
|
|
20
|
+
__exportStar(require("./collapse-white-space.util"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseBrl(value: string): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeEmojis(text: string): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@afilimax/message-text-parser",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Esta é uma biblioteca focada em extrair dados de mensagens de ofertas enviadas por canais do Telegram brasileiros.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/*",
|
|
11
|
+
"!/**/__tests__"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "ts-node ./src/index.ts",
|
|
16
|
+
"format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
|
|
17
|
+
"test": "jest"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"afilimax",
|
|
24
|
+
"offer parser",
|
|
25
|
+
"telegram message"
|
|
26
|
+
],
|
|
27
|
+
"author": "Marcuth",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
|
+
"@types/node": "^25.2.3",
|
|
32
|
+
"eslint": "^10.0.0",
|
|
33
|
+
"eslint-config-prettier": "^10.1.8",
|
|
34
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
35
|
+
"jest": "^30.2.0",
|
|
36
|
+
"prettier": "^3.8.1",
|
|
37
|
+
"prettier-plugin-sort-imports": "^1.8.10",
|
|
38
|
+
"ts-jest": "^29.4.6",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"typescript": "^5.9.3"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"zod": "^4.3.6"
|
|
44
|
+
}
|
|
45
|
+
}
|