@gamastudio/sendwave-provider 1.0.2 → 1.0.4
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/.github/workflows/build.yml +31 -31
- package/README.md +261 -25
- package/build/application/connection/connection-polling.service.d.ts +16 -0
- package/build/application/connection/connection-polling.service.js +49 -0
- package/build/application/message-buffer/message-buffer.service.d.ts +11 -0
- package/build/application/message-buffer/message-buffer.service.js +79 -0
- package/build/application/messaging/message-sender.service.d.ts +40 -0
- package/build/application/messaging/message-sender.service.js +101 -0
- package/build/application/messaging/strategies/interactive.strategy.d.ts +14 -0
- package/build/application/messaging/strategies/interactive.strategy.js +88 -0
- package/build/application/messaging/strategies/list.strategy.d.ts +8 -0
- package/build/application/messaging/strategies/list.strategy.js +61 -0
- package/build/application/messaging/strategies/media.strategy.d.ts +32 -0
- package/build/application/messaging/strategies/media.strategy.js +97 -0
- package/build/application/messaging/strategies/misc.strategy.d.ts +23 -0
- package/build/application/messaging/strategies/misc.strategy.js +95 -0
- package/build/application/messaging/strategies/presence.strategy.d.ts +8 -0
- package/build/application/messaging/strategies/presence.strategy.js +24 -0
- package/build/application/messaging/strategies/send-strategy.interface.d.ts +4 -0
- package/build/application/messaging/strategies/send-strategy.interface.js +2 -0
- package/build/application/messaging/strategies/text.strategy.d.ts +8 -0
- package/build/application/messaging/strategies/text.strategy.js +22 -0
- package/build/application/messaging/strategies/voice.strategy.d.ts +8 -0
- package/build/application/messaging/strategies/voice.strategy.js +37 -0
- package/build/application/queue-flow/queue-flow.service.d.ts +34 -0
- package/build/application/queue-flow/queue-flow.service.js +68 -0
- package/build/config/constants.d.ts +14 -0
- package/build/config/constants.js +17 -0
- package/build/config/defaults.d.ts +8 -0
- package/build/config/defaults.js +110 -0
- package/build/constants/html/error.js +34 -34
- package/build/constants/html/home.js +23 -23
- package/build/constants/svg/wave-error.js +88 -88
- package/build/constants/svg/wave.js +88 -88
- package/build/core/interface/provider.interface.d.ts +2 -1
- package/build/core/interface/types.d.ts +12 -0
- package/build/domain/interfaces/index.d.ts +2 -0
- package/build/domain/interfaces/index.js +18 -0
- package/build/domain/interfaces/parsed-message.interface.d.ts +16 -0
- package/build/domain/interfaces/parsed-message.interface.js +2 -0
- package/build/domain/interfaces/provider.interface.d.ts +21 -0
- package/build/domain/interfaces/provider.interface.js +2 -0
- package/build/domain/types/config.types.d.ts +43 -0
- package/build/domain/types/config.types.js +2 -0
- package/build/domain/types/index.d.ts +2 -0
- package/build/domain/types/index.js +18 -0
- package/build/domain/types/message.types.d.ts +134 -0
- package/build/domain/types/message.types.js +2 -0
- package/build/index.d.ts +5 -4
- package/build/index.js +7 -6
- package/build/infrastructure/http/axios/retry.interceptor.d.ts +2 -0
- package/build/infrastructure/http/axios/retry.interceptor.js +21 -0
- package/build/infrastructure/http/axios/sendwave-api.factory.d.ts +15 -0
- package/build/infrastructure/http/axios/sendwave-api.factory.js +50 -0
- package/build/infrastructure/http/middleware/body-parser.middleware.d.ts +2 -0
- package/build/infrastructure/http/middleware/body-parser.middleware.js +28 -0
- package/build/infrastructure/http/middleware/cors.middleware.d.ts +6 -0
- package/build/infrastructure/http/middleware/cors.middleware.js +8 -0
- package/build/infrastructure/http/middleware/global-args.middleware.d.ts +2 -0
- package/build/infrastructure/http/middleware/global-args.middleware.js +9 -0
- package/build/infrastructure/http/middleware/rate-limiter.middleware.d.ts +4 -0
- package/build/infrastructure/http/middleware/rate-limiter.middleware.js +31 -0
- package/build/infrastructure/http/middleware/static-assets.middleware.d.ts +2 -0
- package/build/infrastructure/http/middleware/static-assets.middleware.js +8 -0
- package/build/infrastructure/http/routes/routes.d.ts +4 -0
- package/build/infrastructure/http/routes/routes.js +56 -0
- package/build/infrastructure/media/media-detector.service.d.ts +27 -0
- package/build/infrastructure/media/media-detector.service.js +123 -0
- package/build/infrastructure/parser/incoming-message.parser.d.ts +2 -0
- package/build/infrastructure/parser/incoming-message.parser.js +41 -0
- package/build/infrastructure/persistence/instance.registry.d.ts +21 -0
- package/build/infrastructure/persistence/instance.registry.js +44 -0
- package/build/infrastructure/persistence/sendwave-api.repository.d.ts +21 -0
- package/build/infrastructure/persistence/sendwave-api.repository.js +64 -0
- package/build/package.json +48 -48
- package/build/presentation/pages/assets/logo.svg.d.ts +1 -0
- package/build/presentation/pages/assets/logo.svg.js +4 -0
- package/build/presentation/pages/assets/wave-error.svg.d.ts +1 -0
- package/build/presentation/pages/assets/wave-error.svg.js +92 -0
- package/build/presentation/pages/assets/wave.svg.d.ts +1 -0
- package/build/presentation/pages/assets/wave.svg.js +92 -0
- package/build/presentation/pages/connect.page.d.ts +1 -0
- package/build/presentation/pages/connect.page.js +182 -0
- package/build/presentation/pages/error.page.d.ts +1 -0
- package/build/presentation/pages/error.page.js +42 -0
- package/build/presentation/pages/home.page.d.ts +1 -0
- package/build/presentation/pages/home.page.js +29 -0
- package/build/presentation/provider/index.d.ts +2 -0
- package/build/presentation/provider/index.js +18 -0
- package/build/presentation/provider/sendwave-core.d.ts +25 -0
- package/build/presentation/provider/sendwave-core.js +125 -0
- package/build/presentation/provider/sendwave.provider.d.ts +73 -0
- package/build/presentation/provider/sendwave.provider.js +359 -0
- package/build/provider/sender.d.ts +3 -1
- package/build/provider/sender.js +52 -34
- package/build/shared/exceptions/payload-too-large.exception.d.ts +4 -0
- package/build/shared/exceptions/payload-too-large.exception.js +11 -0
- package/build/shared/utils/error-extractor.d.ts +1 -0
- package/build/shared/utils/error-extractor.js +7 -0
- package/build/shared/utils/size-parser.d.ts +1 -0
- package/build/shared/utils/size-parser.js +17 -0
- package/package.json +48 -48
- package/tsconfig.json +7 -5
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageSenderService = void 0;
|
|
4
|
+
const text_strategy_1 = require("./strategies/text.strategy");
|
|
5
|
+
const presence_strategy_1 = require("./strategies/presence.strategy");
|
|
6
|
+
const media_strategy_1 = require("./strategies/media.strategy");
|
|
7
|
+
const voice_strategy_1 = require("./strategies/voice.strategy");
|
|
8
|
+
const list_strategy_1 = require("./strategies/list.strategy");
|
|
9
|
+
const interactive_strategy_1 = require("./strategies/interactive.strategy");
|
|
10
|
+
const misc_strategy_1 = require("./strategies/misc.strategy");
|
|
11
|
+
class MessageSenderService {
|
|
12
|
+
constructor(api) {
|
|
13
|
+
this.api = api;
|
|
14
|
+
this.text = new text_strategy_1.TextStrategy(api);
|
|
15
|
+
this.presence = new presence_strategy_1.PresenceStrategy(api);
|
|
16
|
+
this.image = new media_strategy_1.ImageStrategy(api);
|
|
17
|
+
this.video = new media_strategy_1.VideoStrategy(api);
|
|
18
|
+
this.audio = new media_strategy_1.AudioStrategy(api);
|
|
19
|
+
this.file = new media_strategy_1.FileStrategy(api);
|
|
20
|
+
this.voice = new voice_strategy_1.VoiceStrategy(api);
|
|
21
|
+
this.list = new list_strategy_1.ListStrategy(api);
|
|
22
|
+
this.button = new interactive_strategy_1.ButtonStrategy(api);
|
|
23
|
+
this.carousel = new interactive_strategy_1.CarouselStrategy(api);
|
|
24
|
+
this.poll = new misc_strategy_1.PollStrategy(api);
|
|
25
|
+
this.location = new misc_strategy_1.LocationStrategy(api);
|
|
26
|
+
this.reaction = new misc_strategy_1.ReactionStrategy(api);
|
|
27
|
+
this.readMessagesStrategy = new misc_strategy_1.ReadMessagesStrategy(api);
|
|
28
|
+
}
|
|
29
|
+
async dispatch(from, text, options) {
|
|
30
|
+
options = { ...options === null || options === void 0 ? void 0 : options.options };
|
|
31
|
+
if (options === null || options === void 0 ? void 0 : options.media) {
|
|
32
|
+
return this.sendMediaByType({
|
|
33
|
+
from,
|
|
34
|
+
url: options.media,
|
|
35
|
+
text,
|
|
36
|
+
delay: options.delay,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return this.sendText({ from, text });
|
|
40
|
+
}
|
|
41
|
+
async sendMediaByType(data) {
|
|
42
|
+
switch (data.mediaType) {
|
|
43
|
+
case "image":
|
|
44
|
+
return this.sendImage(data);
|
|
45
|
+
case "video":
|
|
46
|
+
return this.sendVideo(data);
|
|
47
|
+
case "audio":
|
|
48
|
+
return this.sendVoice(data);
|
|
49
|
+
case "document":
|
|
50
|
+
return this.sendFile(data);
|
|
51
|
+
default:
|
|
52
|
+
return this.sendText({ from: data.from, text: data.text });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sendText(data) {
|
|
56
|
+
return this.text.send(data);
|
|
57
|
+
}
|
|
58
|
+
sendPresence(data) {
|
|
59
|
+
return this.presence.send(data);
|
|
60
|
+
}
|
|
61
|
+
sendImage(data) {
|
|
62
|
+
return this.image.send(data);
|
|
63
|
+
}
|
|
64
|
+
sendVideo(data) {
|
|
65
|
+
return this.video.send(data);
|
|
66
|
+
}
|
|
67
|
+
sendAudio(data) {
|
|
68
|
+
return this.audio.send(data);
|
|
69
|
+
}
|
|
70
|
+
sendFile(data) {
|
|
71
|
+
return this.file.send(data);
|
|
72
|
+
}
|
|
73
|
+
sendVoice(data) {
|
|
74
|
+
return this.voice.send(data);
|
|
75
|
+
}
|
|
76
|
+
sendList(data) {
|
|
77
|
+
return this.list.send(data);
|
|
78
|
+
}
|
|
79
|
+
sendButton(data) {
|
|
80
|
+
return this.button.send(data);
|
|
81
|
+
}
|
|
82
|
+
sendCarousel(data) {
|
|
83
|
+
return this.carousel.send(data);
|
|
84
|
+
}
|
|
85
|
+
sendPoll(data) {
|
|
86
|
+
return this.poll.send(data);
|
|
87
|
+
}
|
|
88
|
+
sendLocation(data) {
|
|
89
|
+
return this.location.send(data);
|
|
90
|
+
}
|
|
91
|
+
sendReaction(data) {
|
|
92
|
+
return this.reaction.send(data);
|
|
93
|
+
}
|
|
94
|
+
sendMedia(data) {
|
|
95
|
+
return this.sendMediaByType(data);
|
|
96
|
+
}
|
|
97
|
+
readMessages(data) {
|
|
98
|
+
return this.readMessagesStrategy.send(data);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.MessageSenderService = MessageSenderService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { Button, SendButton, SendCarousel } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare function normalizeButton(button: Button | string, index: number): any;
|
|
5
|
+
export declare class ButtonStrategy implements SendStrategy<SendButton> {
|
|
6
|
+
private readonly api;
|
|
7
|
+
constructor(api: SendWaveApiRepository);
|
|
8
|
+
send(data: SendButton): Promise<any>;
|
|
9
|
+
}
|
|
10
|
+
export declare class CarouselStrategy implements SendStrategy<SendCarousel> {
|
|
11
|
+
private readonly api;
|
|
12
|
+
constructor(api: SendWaveApiRepository);
|
|
13
|
+
send(data: SendCarousel): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CarouselStrategy = exports.ButtonStrategy = void 0;
|
|
4
|
+
exports.normalizeButton = normalizeButton;
|
|
5
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
6
|
+
function normalizeButton(button, index) {
|
|
7
|
+
if (typeof button === "string") {
|
|
8
|
+
return { type: "reply", displayText: button, id: `${index + 1}` };
|
|
9
|
+
}
|
|
10
|
+
const raw = button;
|
|
11
|
+
const { type = "reply", displayText, ...rest } = raw;
|
|
12
|
+
const base = {
|
|
13
|
+
type,
|
|
14
|
+
displayText: displayText || raw.text || "",
|
|
15
|
+
id: `${index + 1}`,
|
|
16
|
+
...rest,
|
|
17
|
+
};
|
|
18
|
+
delete base.text;
|
|
19
|
+
delete base.body;
|
|
20
|
+
delete base.reply;
|
|
21
|
+
return base;
|
|
22
|
+
}
|
|
23
|
+
class ButtonStrategy {
|
|
24
|
+
constructor(api) {
|
|
25
|
+
this.api = api;
|
|
26
|
+
}
|
|
27
|
+
async send(data) {
|
|
28
|
+
var _a;
|
|
29
|
+
try {
|
|
30
|
+
return await this.api.sendButtons({
|
|
31
|
+
number: data.from,
|
|
32
|
+
thumbnailUrl: data.thumbnailUrl,
|
|
33
|
+
title: data.title,
|
|
34
|
+
body: data.body,
|
|
35
|
+
description: data.description,
|
|
36
|
+
footer: data.footer,
|
|
37
|
+
buttons: data.buttons.map((button, index) => normalizeButton(button, index)),
|
|
38
|
+
delay: data.delay || 2000,
|
|
39
|
+
quoted: data.quoted,
|
|
40
|
+
everyOne: data.everyOne || false,
|
|
41
|
+
mentioned: ((_a = data.mentioned) === null || _a === void 0 ? void 0 : _a.length) ? data.mentioned : [data.from],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
46
|
+
console.error(`[sendButton Error] ${msg}`);
|
|
47
|
+
throw new Error(msg);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ButtonStrategy = ButtonStrategy;
|
|
52
|
+
class CarouselStrategy {
|
|
53
|
+
constructor(api) {
|
|
54
|
+
this.api = api;
|
|
55
|
+
}
|
|
56
|
+
async send(data) {
|
|
57
|
+
var _a;
|
|
58
|
+
try {
|
|
59
|
+
if (!(data === null || data === void 0 ? void 0 : data.from))
|
|
60
|
+
throw new Error("sendCarousel: falta 'from'");
|
|
61
|
+
if (!Array.isArray(data.cards) || data.cards.length === 0)
|
|
62
|
+
throw new Error("sendCarousel: 'cards' debe ser un array no vacío");
|
|
63
|
+
const cards = data.cards.map((card, cardIndex) => ({
|
|
64
|
+
text: card.text,
|
|
65
|
+
thumbnailUrl: card.thumbnailUrl,
|
|
66
|
+
footerText: card.footerText,
|
|
67
|
+
buttons: (card.buttons || []).map((button, buttonIndex) => normalizeButton(button, cardIndex * 100 + buttonIndex)),
|
|
68
|
+
}));
|
|
69
|
+
return await this.api.sendCarousel({
|
|
70
|
+
number: data.from,
|
|
71
|
+
title: data.title,
|
|
72
|
+
description: data.description,
|
|
73
|
+
footer: data.footer,
|
|
74
|
+
cards,
|
|
75
|
+
delay: data.delay || 2000,
|
|
76
|
+
quoted: data.quoted,
|
|
77
|
+
everyOne: data.everyOne || false,
|
|
78
|
+
mentioned: ((_a = data.mentioned) === null || _a === void 0 ? void 0 : _a.length) ? data.mentioned : [data.from],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
83
|
+
console.error(`[sendCarousel Error] ${msg}`);
|
|
84
|
+
throw new Error(msg);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.CarouselStrategy = CarouselStrategy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendList } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare class ListStrategy implements SendStrategy<SendList> {
|
|
5
|
+
private readonly api;
|
|
6
|
+
constructor(api: SendWaveApiRepository);
|
|
7
|
+
send(data: SendList): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ListStrategy = void 0;
|
|
4
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
5
|
+
class ListStrategy {
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
}
|
|
9
|
+
async send(data) {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
if (!(data === null || data === void 0 ? void 0 : data.from))
|
|
13
|
+
throw new Error("sendList: falta 'from'");
|
|
14
|
+
if (!(data === null || data === void 0 ? void 0 : data.list))
|
|
15
|
+
throw new Error("sendList: falta 'list'");
|
|
16
|
+
const { title, description = "", footerText = "", button, content = [], } = data.list;
|
|
17
|
+
if (!Array.isArray(content) || content.length === 0)
|
|
18
|
+
throw new Error("sendList: 'content' debe ser un array no vacío");
|
|
19
|
+
const isSimple = typeof content[0] === "string";
|
|
20
|
+
const sections = isSimple
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
title: "",
|
|
24
|
+
rows: content.map((t, i) => ({
|
|
25
|
+
rowId: `${i + 1}`,
|
|
26
|
+
title: t,
|
|
27
|
+
})),
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
: content.map((sec) => ({
|
|
31
|
+
title: sec.title || "",
|
|
32
|
+
rows: (sec.rows || []).map((r, i) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return ({
|
|
35
|
+
rowId: `${i + 1}`,
|
|
36
|
+
title: r.title || "",
|
|
37
|
+
...(((_a = r.description) === null || _a === void 0 ? void 0 : _a.trim())
|
|
38
|
+
? { description: r.description.trim() }
|
|
39
|
+
: {}),
|
|
40
|
+
});
|
|
41
|
+
}),
|
|
42
|
+
}));
|
|
43
|
+
return await this.api.sendList({
|
|
44
|
+
number: data.from,
|
|
45
|
+
title,
|
|
46
|
+
description,
|
|
47
|
+
footerText,
|
|
48
|
+
buttonText: button,
|
|
49
|
+
sections,
|
|
50
|
+
delay: data.delay || 2000,
|
|
51
|
+
quoted: data.quoted,
|
|
52
|
+
everyOne: data.everyOne || false,
|
|
53
|
+
mentioned: ((_a = data.mentioned) === null || _a === void 0 ? void 0 : _a.length) ? data.mentioned : [data.from],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
console.error("[sendList Error]", (0, error_extractor_1.extractApiError)(err));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ListStrategy = ListStrategy;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendMedia } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare abstract class BaseMediaStrategy implements SendStrategy<SendMedia> {
|
|
5
|
+
protected readonly api: SendWaveApiRepository;
|
|
6
|
+
protected abstract readonly mediaType: string;
|
|
7
|
+
constructor(api: SendWaveApiRepository);
|
|
8
|
+
send(data: SendMedia): Promise<any>;
|
|
9
|
+
protected abstract getMimeType(): string;
|
|
10
|
+
protected abstract getExtension(): string;
|
|
11
|
+
protected handleError(error: any): never;
|
|
12
|
+
}
|
|
13
|
+
export declare class ImageStrategy extends BaseMediaStrategy {
|
|
14
|
+
protected readonly mediaType = "image";
|
|
15
|
+
protected getMimeType(): string;
|
|
16
|
+
protected getExtension(): string;
|
|
17
|
+
}
|
|
18
|
+
export declare class VideoStrategy extends BaseMediaStrategy {
|
|
19
|
+
protected readonly mediaType = "video";
|
|
20
|
+
protected getMimeType(): string;
|
|
21
|
+
protected getExtension(): string;
|
|
22
|
+
}
|
|
23
|
+
export declare class AudioStrategy extends BaseMediaStrategy {
|
|
24
|
+
protected readonly mediaType = "audio";
|
|
25
|
+
protected getMimeType(): string;
|
|
26
|
+
protected getExtension(): string;
|
|
27
|
+
}
|
|
28
|
+
export declare class FileStrategy extends BaseMediaStrategy {
|
|
29
|
+
protected readonly mediaType = "document";
|
|
30
|
+
protected getMimeType(): string;
|
|
31
|
+
protected getExtension(): string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileStrategy = exports.AudioStrategy = exports.VideoStrategy = exports.ImageStrategy = exports.BaseMediaStrategy = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
6
|
+
class BaseMediaStrategy {
|
|
7
|
+
constructor(api) {
|
|
8
|
+
this.api = api;
|
|
9
|
+
}
|
|
10
|
+
async send(data) {
|
|
11
|
+
try {
|
|
12
|
+
return await this.api.sendMedia({
|
|
13
|
+
number: data.from,
|
|
14
|
+
mediatype: this.mediaType,
|
|
15
|
+
mimetype: this.getMimeType(),
|
|
16
|
+
fileName: data.fileName || `${(0, crypto_1.randomUUID)()}.${this.getExtension()}`,
|
|
17
|
+
media: data.url,
|
|
18
|
+
caption: data.text,
|
|
19
|
+
delay: data.delay || 0,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
this.handleError(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
handleError(error) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("exceeds limit")) {
|
|
29
|
+
console.error(`[SendMedia Error] File size validation failed: ${error.message}`);
|
|
30
|
+
throw new Error(`File too large: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 413) {
|
|
33
|
+
console.error("[SendMedia Error] Server rejected large payload");
|
|
34
|
+
throw new Error("File too large for server");
|
|
35
|
+
}
|
|
36
|
+
if (error.code === "ECONNABORTED") {
|
|
37
|
+
console.error("[SendMedia Error] Request timeout - file may be too large");
|
|
38
|
+
throw new Error("Upload timeout - file may be too large");
|
|
39
|
+
}
|
|
40
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
41
|
+
console.error(`[SendMedia Error] ${msg}`);
|
|
42
|
+
throw new Error(msg);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.BaseMediaStrategy = BaseMediaStrategy;
|
|
46
|
+
class ImageStrategy extends BaseMediaStrategy {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.mediaType = "image";
|
|
50
|
+
}
|
|
51
|
+
getMimeType() {
|
|
52
|
+
return "image/jpeg";
|
|
53
|
+
}
|
|
54
|
+
getExtension() {
|
|
55
|
+
return "jpg";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ImageStrategy = ImageStrategy;
|
|
59
|
+
class VideoStrategy extends BaseMediaStrategy {
|
|
60
|
+
constructor() {
|
|
61
|
+
super(...arguments);
|
|
62
|
+
this.mediaType = "video";
|
|
63
|
+
}
|
|
64
|
+
getMimeType() {
|
|
65
|
+
return "video/mp4";
|
|
66
|
+
}
|
|
67
|
+
getExtension() {
|
|
68
|
+
return "mp4";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.VideoStrategy = VideoStrategy;
|
|
72
|
+
class AudioStrategy extends BaseMediaStrategy {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(...arguments);
|
|
75
|
+
this.mediaType = "audio";
|
|
76
|
+
}
|
|
77
|
+
getMimeType() {
|
|
78
|
+
return "audio/mpeg";
|
|
79
|
+
}
|
|
80
|
+
getExtension() {
|
|
81
|
+
return "mp3";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.AudioStrategy = AudioStrategy;
|
|
85
|
+
class FileStrategy extends BaseMediaStrategy {
|
|
86
|
+
constructor() {
|
|
87
|
+
super(...arguments);
|
|
88
|
+
this.mediaType = "document";
|
|
89
|
+
}
|
|
90
|
+
getMimeType() {
|
|
91
|
+
return "application/octet-stream";
|
|
92
|
+
}
|
|
93
|
+
getExtension() {
|
|
94
|
+
return "bin";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.FileStrategy = FileStrategy;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendPoll, SendLocation, SendReaction, ReadMessage } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare class PollStrategy implements SendStrategy<SendPoll> {
|
|
5
|
+
private readonly api;
|
|
6
|
+
constructor(api: SendWaveApiRepository);
|
|
7
|
+
send(data: SendPoll): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export declare class LocationStrategy implements SendStrategy<SendLocation> {
|
|
10
|
+
private readonly api;
|
|
11
|
+
constructor(api: SendWaveApiRepository);
|
|
12
|
+
send(data: SendLocation): Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ReactionStrategy implements SendStrategy<SendReaction> {
|
|
15
|
+
private readonly api;
|
|
16
|
+
constructor(api: SendWaveApiRepository);
|
|
17
|
+
send(data: SendReaction): Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
export declare class ReadMessagesStrategy implements SendStrategy<ReadMessage> {
|
|
20
|
+
private readonly api;
|
|
21
|
+
constructor(api: SendWaveApiRepository);
|
|
22
|
+
send(data: ReadMessage): Promise<any>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadMessagesStrategy = exports.ReactionStrategy = exports.LocationStrategy = exports.PollStrategy = void 0;
|
|
4
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
5
|
+
class PollStrategy {
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
}
|
|
9
|
+
async send(data) {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
return await this.api.sendPoll({
|
|
13
|
+
number: data.from,
|
|
14
|
+
name: data.poll.name,
|
|
15
|
+
selectableCount: data.poll.selectableCount || 1,
|
|
16
|
+
values: data.poll.values,
|
|
17
|
+
delay: data.delay || 2000,
|
|
18
|
+
quoted: data.quoted,
|
|
19
|
+
everyOne: data.everyOne || false,
|
|
20
|
+
mentioned: ((_a = data.mentioned) === null || _a === void 0 ? void 0 : _a.length) ? data.mentioned : [data.from],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
25
|
+
console.error(`[sendPoll Error] ${msg}`);
|
|
26
|
+
throw new Error(msg);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.PollStrategy = PollStrategy;
|
|
31
|
+
class LocationStrategy {
|
|
32
|
+
constructor(api) {
|
|
33
|
+
this.api = api;
|
|
34
|
+
}
|
|
35
|
+
async send(data) {
|
|
36
|
+
try {
|
|
37
|
+
return await this.api.sendLocation({
|
|
38
|
+
number: data.from,
|
|
39
|
+
name: data.name,
|
|
40
|
+
address: data.address,
|
|
41
|
+
latitude: data.latitude,
|
|
42
|
+
longitude: data.longitude,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
47
|
+
console.error(`[sendLocation Error] ${msg}`);
|
|
48
|
+
throw new Error(msg);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.LocationStrategy = LocationStrategy;
|
|
53
|
+
class ReactionStrategy {
|
|
54
|
+
constructor(api) {
|
|
55
|
+
this.api = api;
|
|
56
|
+
}
|
|
57
|
+
async send(data) {
|
|
58
|
+
try {
|
|
59
|
+
return await this.api.sendReaction({
|
|
60
|
+
key: data.key,
|
|
61
|
+
reaction: data.reaction,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
66
|
+
console.error(`[sendReaction Error] ${msg}`);
|
|
67
|
+
throw new Error(msg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ReactionStrategy = ReactionStrategy;
|
|
72
|
+
class ReadMessagesStrategy {
|
|
73
|
+
constructor(api) {
|
|
74
|
+
this.api = api;
|
|
75
|
+
}
|
|
76
|
+
async send(data) {
|
|
77
|
+
try {
|
|
78
|
+
return await this.api.markMessagesAsRead({
|
|
79
|
+
readMessages: [
|
|
80
|
+
{
|
|
81
|
+
remoteJid: data.from,
|
|
82
|
+
fromMe: false,
|
|
83
|
+
id: data.messageId,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
90
|
+
console.error(`[readMessage Error] ${msg}`);
|
|
91
|
+
throw new Error(msg);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.ReadMessagesStrategy = ReadMessagesStrategy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendPresence } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare class PresenceStrategy implements SendStrategy<SendPresence> {
|
|
5
|
+
private readonly api;
|
|
6
|
+
constructor(api: SendWaveApiRepository);
|
|
7
|
+
send(data: SendPresence): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PresenceStrategy = void 0;
|
|
4
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
5
|
+
class PresenceStrategy {
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
}
|
|
9
|
+
async send(data) {
|
|
10
|
+
try {
|
|
11
|
+
return await this.api.sendPresence({
|
|
12
|
+
number: data.from,
|
|
13
|
+
delay: data.delay || 2000,
|
|
14
|
+
presence: data.presence || "composing",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
19
|
+
console.error(`[sendPresence Error] ${msg}`);
|
|
20
|
+
throw new Error(msg);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PresenceStrategy = PresenceStrategy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendMessage } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare class TextStrategy implements SendStrategy<SendMessage> {
|
|
5
|
+
private readonly api;
|
|
6
|
+
constructor(api: SendWaveApiRepository);
|
|
7
|
+
send(data: SendMessage): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextStrategy = void 0;
|
|
4
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
5
|
+
class TextStrategy {
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
}
|
|
9
|
+
async send(data) {
|
|
10
|
+
try {
|
|
11
|
+
return await this.api.sendText({
|
|
12
|
+
delay: data.delay || 2000,
|
|
13
|
+
number: data.from,
|
|
14
|
+
text: data.text,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(`[sendText Error] ${(0, error_extractor_1.extractApiError)(error)}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TextStrategy = TextStrategy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SendWaveApiRepository } from "../../../infrastructure/persistence/sendwave-api.repository";
|
|
2
|
+
import { SendMedia } from "../../../domain/types";
|
|
3
|
+
import { SendStrategy } from "./send-strategy.interface";
|
|
4
|
+
export declare class VoiceStrategy implements SendStrategy<SendMedia> {
|
|
5
|
+
private readonly api;
|
|
6
|
+
constructor(api: SendWaveApiRepository);
|
|
7
|
+
send(data: SendMedia): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoiceStrategy = void 0;
|
|
4
|
+
const error_extractor_1 = require("../../../shared/utils/error-extractor");
|
|
5
|
+
class VoiceStrategy {
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
|
+
}
|
|
9
|
+
async send(data) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
try {
|
|
12
|
+
return await this.api.sendWhatsAppAudio({
|
|
13
|
+
number: data.from,
|
|
14
|
+
audio: data.url,
|
|
15
|
+
delay: data.delay || 2000,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("exceeds limit")) {
|
|
20
|
+
console.error(`[SendVoice Error] File size validation failed: ${error.message}`);
|
|
21
|
+
throw new Error(`Audio file too large: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 413) {
|
|
24
|
+
console.error("[SendVoice Error] Server rejected large payload");
|
|
25
|
+
throw new Error("Audio file too large for server");
|
|
26
|
+
}
|
|
27
|
+
if (error.code === "ECONNABORTED") {
|
|
28
|
+
console.error("[SendVoice Error] Request timeout - audio file may be too large");
|
|
29
|
+
throw new Error("Upload timeout - audio file may be too large");
|
|
30
|
+
}
|
|
31
|
+
const msg = (0, error_extractor_1.extractApiError)(error);
|
|
32
|
+
console.error(`[SendVoice Error] ${msg}`);
|
|
33
|
+
throw new Error(msg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.VoiceStrategy = VoiceStrategy;
|