nesthub 1.0.0 → 1.0.2
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/README.md +0 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/queue/README.md +1 -1
- package/dist/queue/index.d.ts +4 -9
- package/dist/queue/index.js +5 -1
- package/dist/queue/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/queue/README.md +1 -1
- package/dist/cache/index.spec.d.ts +0 -1
- package/dist/cache/index.spec.js +0 -61
- package/dist/cache/index.spec.js.map +0 -1
- package/dist/excel/excel.module.d.ts +0 -2
- package/dist/excel/excel.module.js +0 -21
- package/dist/excel/excel.module.js.map +0 -1
- package/dist/excel/interfaces.d.ts +0 -19
- package/dist/excel/interfaces.js +0 -3
- package/dist/excel/interfaces.js.map +0 -1
- package/dist/index.spec.d.ts +0 -1
- package/dist/index.spec.js +0 -11
- package/dist/index.spec.js.map +0 -1
- package/dist/notification/email/index.d.ts +0 -62
- package/dist/notification/email/index.js +0 -253
- package/dist/notification/email/index.js.map +0 -1
- package/dist/notification/email/index.spec.d.ts +0 -1
- package/dist/notification/email/index.spec.js +0 -121
- package/dist/notification/email/index.spec.js.map +0 -1
- package/dist/notification/firebase/index.d.ts +0 -52
- package/dist/notification/firebase/index.js +0 -261
- package/dist/notification/firebase/index.js.map +0 -1
- package/dist/notification/firebase/index.spec.d.ts +0 -1
- package/dist/notification/firebase/index.spec.js +0 -114
- package/dist/notification/firebase/index.spec.js.map +0 -1
- package/dist/notification/index.spec.d.ts +0 -1
- package/dist/notification/index.spec.js +0 -336
- package/dist/notification/index.spec.js.map +0 -1
- package/dist/notification/shared.d.ts +0 -48
- package/dist/notification/shared.js +0 -95
- package/dist/notification/shared.js.map +0 -1
- package/dist/notification/sms/index.d.ts +0 -52
- package/dist/notification/sms/index.js +0 -234
- package/dist/notification/sms/index.js.map +0 -1
- package/dist/notification/sms/index.spec.d.ts +0 -1
- package/dist/notification/sms/index.spec.js +0 -123
- package/dist/notification/sms/index.spec.js.map +0 -1
- package/dist/notification/telegram/index.d.ts +0 -50
- package/dist/notification/telegram/index.js +0 -248
- package/dist/notification/telegram/index.js.map +0 -1
- package/dist/notification/telegram/index.spec.d.ts +0 -1
- package/dist/notification/telegram/index.spec.js +0 -108
- package/dist/notification/telegram/index.spec.js.map +0 -1
- package/dist/notification/typeorm-storage.d.ts +0 -28
- package/dist/notification/typeorm-storage.js +0 -56
- package/dist/notification/typeorm-storage.js.map +0 -1
- package/dist/notification/unified.d.ts +0 -47
- package/dist/notification/unified.js +0 -207
- package/dist/notification/unified.js.map +0 -1
- package/dist/queue/index.spec.d.ts +0 -1
- package/dist/queue/index.spec.js +0 -76
- package/dist/queue/index.spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/typeorm/index.spec.d.ts +0 -1
- package/dist/typeorm/index.spec.js +0 -109
- package/dist/typeorm/index.spec.js.map +0 -1
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var SmsModule_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.SmsModule = exports.SMS_SERVICE = void 0;
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const shared_1 = require("../shared");
|
|
19
|
-
const typeorm_storage_1 = require("../typeorm-storage");
|
|
20
|
-
exports.SMS_SERVICE = 'SMS_SERVICE';
|
|
21
|
-
let SmsServiceImpl = class SmsServiceImpl {
|
|
22
|
-
options;
|
|
23
|
-
injectedStorage;
|
|
24
|
-
templateService = new shared_1.TemplateService();
|
|
25
|
-
twilioClient;
|
|
26
|
-
queueClient;
|
|
27
|
-
workerClient;
|
|
28
|
-
storage;
|
|
29
|
-
constructor(options, injectedStorage) {
|
|
30
|
-
this.options = options;
|
|
31
|
-
this.injectedStorage = injectedStorage;
|
|
32
|
-
this.storage =
|
|
33
|
-
injectedStorage ??
|
|
34
|
-
options.storage?.provider ??
|
|
35
|
-
new shared_1.ConsoleNotificationStorage();
|
|
36
|
-
}
|
|
37
|
-
async onModuleInit() {
|
|
38
|
-
const { templates, twilio, queue } = this.options;
|
|
39
|
-
if (templates?.dir)
|
|
40
|
-
await this.templateService.loadFromDir(templates.dir);
|
|
41
|
-
if (templates?.templates)
|
|
42
|
-
this.templateService.loadFromRecord(templates.templates);
|
|
43
|
-
if (twilio?.accountSid && twilio?.authToken) {
|
|
44
|
-
try {
|
|
45
|
-
const twilioModule = (await (0, shared_1.dynamicImport)('twilio'));
|
|
46
|
-
this.twilioClient = twilioModule.default(twilio.accountSid, twilio.authToken);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
console.warn('[SmsModule] twilio not installed. Falling back to console.');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (queue?.useQueue && queue?.connection?.url) {
|
|
53
|
-
try {
|
|
54
|
-
const bullmqModule = (await (0, shared_1.dynamicImport)('bullmq'));
|
|
55
|
-
const queueName = queue.prefix ?? 'sms-notifications';
|
|
56
|
-
this.queueClient = new bullmqModule.Queue(queueName, {
|
|
57
|
-
connection: { url: queue.connection.url },
|
|
58
|
-
defaultJobOptions: queue.defaultJobOptions,
|
|
59
|
-
});
|
|
60
|
-
if (queue.worker !== false) {
|
|
61
|
-
this.workerClient = new bullmqModule.Worker(queueName, async (job) => this.processQueuedJob(job), {
|
|
62
|
-
connection: { url: queue.connection.url },
|
|
63
|
-
concurrency: queue.concurrency ?? 1,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
console.warn('[SmsModule] bullmq not installed. Queue mode disabled.');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async onModuleDestroy() {
|
|
73
|
-
await this.workerClient?.close();
|
|
74
|
-
await this.queueClient?.close();
|
|
75
|
-
}
|
|
76
|
-
async sendSms(options) {
|
|
77
|
-
if ((options.mode ?? 'direct') === 'queue' && this.queueClient) {
|
|
78
|
-
return this.enqueue(options);
|
|
79
|
-
}
|
|
80
|
-
return this.sendNow(options);
|
|
81
|
-
}
|
|
82
|
-
async cancelJob(dedupId) {
|
|
83
|
-
if (!this.queueClient)
|
|
84
|
-
return;
|
|
85
|
-
const record = await this.storage.findByDedupId(dedupId);
|
|
86
|
-
if (!record || record.status !== 'pending')
|
|
87
|
-
return;
|
|
88
|
-
try {
|
|
89
|
-
await this.queueClient.remove(record.id);
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
}
|
|
93
|
-
await this.storage.update(record.id, { status: 'cancelled' });
|
|
94
|
-
}
|
|
95
|
-
async processQueuedJob(job) {
|
|
96
|
-
const { data } = job;
|
|
97
|
-
if (data.expiresAt && new Date(data.expiresAt) < new Date()) {
|
|
98
|
-
await this.storage.update(job.id, {
|
|
99
|
-
status: 'expired',
|
|
100
|
-
error: 'Expired before processing',
|
|
101
|
-
});
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (data.dedupId) {
|
|
105
|
-
const record = await this.storage.findByDedupId(data.dedupId);
|
|
106
|
-
if (record &&
|
|
107
|
-
(record.status === 'cancelled' || record.status === 'expired'))
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const result = await this.sendNow(data);
|
|
111
|
-
await this.storage.update(job.id, {
|
|
112
|
-
status: result.success ? 'sent' : 'failed',
|
|
113
|
-
messageId: result.messageId,
|
|
114
|
-
error: result.error,
|
|
115
|
-
sentAt: new Date().toISOString(),
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async sendNow(options) {
|
|
119
|
-
try {
|
|
120
|
-
const { to, body, template, context = {}, locale, from } = options;
|
|
121
|
-
const resolvedLocale = locale ?? this.options.defaultLocale ?? 'en';
|
|
122
|
-
const ctx = { ...context, locale: resolvedLocale };
|
|
123
|
-
let resolvedBody = body;
|
|
124
|
-
if (template) {
|
|
125
|
-
const tmplName = this.templateService.resolveName(template, resolvedLocale);
|
|
126
|
-
if (!resolvedBody) {
|
|
127
|
-
resolvedBody =
|
|
128
|
-
this.templateService.render(`body:${tmplName}`, ctx) ||
|
|
129
|
-
this.templateService.render(tmplName, ctx);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (!resolvedBody) {
|
|
133
|
-
return { success: false, error: 'No content to send' };
|
|
134
|
-
}
|
|
135
|
-
if (this.twilioClient) {
|
|
136
|
-
const message = await this.twilioClient.messages.create({
|
|
137
|
-
to,
|
|
138
|
-
from: from ?? this.options.twilio?.from ?? this.options.defaultFrom,
|
|
139
|
-
body: resolvedBody,
|
|
140
|
-
});
|
|
141
|
-
return { success: true, messageId: message.sid };
|
|
142
|
-
}
|
|
143
|
-
console.log('[SmsService] SMS:', JSON.stringify({ to, from, body: resolvedBody }));
|
|
144
|
-
return { success: true, messageId: `mock-${Date.now()}` };
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
148
|
-
return { success: false, error: message };
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async enqueue(options) {
|
|
152
|
-
try {
|
|
153
|
-
const jobOpts = {};
|
|
154
|
-
if (options.dedupId)
|
|
155
|
-
jobOpts.deduplication = { id: options.dedupId };
|
|
156
|
-
const job = await this.queueClient.add('send-sms', options, jobOpts);
|
|
157
|
-
await this.storage.save({
|
|
158
|
-
id: job.id ?? '',
|
|
159
|
-
to: options.to,
|
|
160
|
-
body: options.body,
|
|
161
|
-
template: options.template,
|
|
162
|
-
channel: 'sms',
|
|
163
|
-
status: 'pending',
|
|
164
|
-
expiresAt: options.expiresAt
|
|
165
|
-
? new Date(options.expiresAt).toISOString()
|
|
166
|
-
: undefined,
|
|
167
|
-
dedupId: options.dedupId,
|
|
168
|
-
createdAt: new Date().toISOString(),
|
|
169
|
-
});
|
|
170
|
-
return { success: true, messageId: job.id, jobId: job.id };
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
174
|
-
return { success: false, error: message };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
SmsServiceImpl = __decorate([
|
|
179
|
-
(0, common_1.Injectable)(),
|
|
180
|
-
__param(0, (0, common_1.Inject)('SMS_MODULE_OPTIONS')),
|
|
181
|
-
__param(1, (0, common_1.Optional)()),
|
|
182
|
-
__param(1, (0, common_1.Inject)(shared_1.NOTIFICATION_STORAGE)),
|
|
183
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
184
|
-
], SmsServiceImpl);
|
|
185
|
-
let SmsModule = SmsModule_1 = class SmsModule {
|
|
186
|
-
static forRoot(options = {}) {
|
|
187
|
-
const providers = [
|
|
188
|
-
{ provide: 'SMS_MODULE_OPTIONS', useValue: options },
|
|
189
|
-
{ provide: exports.SMS_SERVICE, useClass: SmsServiceImpl },
|
|
190
|
-
];
|
|
191
|
-
const imports = [];
|
|
192
|
-
if (options.storage?.typeorm) {
|
|
193
|
-
try {
|
|
194
|
-
const { TypeOrmModule, getRepositoryToken } = (0, typeorm_storage_1.getTypeOrmHelpers)();
|
|
195
|
-
const entity = (0, typeorm_storage_1.getOrCreateEntity)();
|
|
196
|
-
imports.push(TypeOrmModule.forFeature([entity]));
|
|
197
|
-
providers.push({
|
|
198
|
-
provide: shared_1.NOTIFICATION_STORAGE,
|
|
199
|
-
useFactory: (repo) => new typeorm_storage_1.TypeOrmNotificationStorage(repo),
|
|
200
|
-
inject: [getRepositoryToken(entity)],
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
catch {
|
|
204
|
-
throw new Error('SmsModule: @nestjs/typeorm and typeorm must be installed when storage.typeorm is true');
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
module: SmsModule_1,
|
|
209
|
-
imports,
|
|
210
|
-
providers,
|
|
211
|
-
exports: [exports.SMS_SERVICE],
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
static forRootAsync(options) {
|
|
215
|
-
return {
|
|
216
|
-
module: SmsModule_1,
|
|
217
|
-
providers: [
|
|
218
|
-
{
|
|
219
|
-
provide: 'SMS_MODULE_OPTIONS',
|
|
220
|
-
useFactory: options.useFactory,
|
|
221
|
-
inject: options.inject ?? [],
|
|
222
|
-
},
|
|
223
|
-
{ provide: exports.SMS_SERVICE, useClass: SmsServiceImpl },
|
|
224
|
-
],
|
|
225
|
-
exports: [exports.SMS_SERVICE],
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
exports.SmsModule = SmsModule;
|
|
230
|
-
exports.SmsModule = SmsModule = SmsModule_1 = __decorate([
|
|
231
|
-
(0, common_1.Global)(),
|
|
232
|
-
(0, common_1.Module)({})
|
|
233
|
-
], SmsModule);
|
|
234
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js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S;IAFrB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,SAAS,CAqDrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
let nextJobId = 1;
|
|
4
|
-
jest.mock('bullmq', () => ({
|
|
5
|
-
Queue: jest.fn().mockImplementation(() => ({
|
|
6
|
-
add: jest
|
|
7
|
-
.fn()
|
|
8
|
-
.mockImplementation(() => Promise.resolve({ id: `sms-job-${nextJobId++}` })),
|
|
9
|
-
remove: jest.fn().mockResolvedValue(undefined),
|
|
10
|
-
close: jest.fn().mockResolvedValue(undefined),
|
|
11
|
-
})),
|
|
12
|
-
Worker: jest.fn().mockImplementation(() => ({
|
|
13
|
-
close: jest.fn().mockResolvedValue(undefined),
|
|
14
|
-
})),
|
|
15
|
-
}));
|
|
16
|
-
const testing_1 = require("@nestjs/testing");
|
|
17
|
-
const index_1 = require("./index");
|
|
18
|
-
describe('@vn.chemgio/nestjs-utilities/notification/sms', () => {
|
|
19
|
-
let service;
|
|
20
|
-
let module;
|
|
21
|
-
afterEach(async () => {
|
|
22
|
-
if (module)
|
|
23
|
-
await module.close();
|
|
24
|
-
});
|
|
25
|
-
it('should send SMS via console fallback', async () => {
|
|
26
|
-
module = await testing_1.Test.createTestingModule({
|
|
27
|
-
imports: [
|
|
28
|
-
index_1.SmsModule.forRoot({
|
|
29
|
-
twilio: { accountSid: 'sid', authToken: 'token' },
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
32
|
-
}).compile();
|
|
33
|
-
await module.init();
|
|
34
|
-
service = module.get(index_1.SMS_SERVICE);
|
|
35
|
-
const result = await service.sendSms({ to: '+84123456789', body: 'Hello' });
|
|
36
|
-
expect(result.success).toBe(true);
|
|
37
|
-
expect(result.messageId).toMatch(/^mock-/);
|
|
38
|
-
});
|
|
39
|
-
it('should return no-content error', async () => {
|
|
40
|
-
module = await testing_1.Test.createTestingModule({
|
|
41
|
-
imports: [
|
|
42
|
-
index_1.SmsModule.forRoot({
|
|
43
|
-
twilio: { accountSid: 'sid', authToken: 'token' },
|
|
44
|
-
}),
|
|
45
|
-
],
|
|
46
|
-
}).compile();
|
|
47
|
-
await module.init();
|
|
48
|
-
service = module.get(index_1.SMS_SERVICE);
|
|
49
|
-
const result = await service.sendSms({ to: '+84123456789' });
|
|
50
|
-
expect(result.success).toBe(false);
|
|
51
|
-
expect(result.error).toBe('No content to send');
|
|
52
|
-
});
|
|
53
|
-
it('should render handlebars template', async () => {
|
|
54
|
-
module = await testing_1.Test.createTestingModule({
|
|
55
|
-
imports: [
|
|
56
|
-
index_1.SmsModule.forRoot({
|
|
57
|
-
twilio: { accountSid: 'sid', authToken: 'token' },
|
|
58
|
-
templates: {
|
|
59
|
-
templates: {
|
|
60
|
-
otp: { body: 'Your code is {{code}}' },
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
}),
|
|
64
|
-
],
|
|
65
|
-
}).compile();
|
|
66
|
-
await module.init();
|
|
67
|
-
service = module.get(index_1.SMS_SERVICE);
|
|
68
|
-
const result = await service.sendSms({
|
|
69
|
-
to: '+84123456789',
|
|
70
|
-
template: 'otp',
|
|
71
|
-
context: { code: '123456' },
|
|
72
|
-
});
|
|
73
|
-
expect(result.success).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
it('should queue SMS and save pending record', async () => {
|
|
76
|
-
module = await testing_1.Test.createTestingModule({
|
|
77
|
-
imports: [
|
|
78
|
-
index_1.SmsModule.forRoot({
|
|
79
|
-
twilio: { accountSid: 'sid', authToken: 'token' },
|
|
80
|
-
queue: {
|
|
81
|
-
useQueue: true,
|
|
82
|
-
connection: { url: 'redis://localhost:6379' },
|
|
83
|
-
worker: false,
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
],
|
|
87
|
-
}).compile();
|
|
88
|
-
await module.init();
|
|
89
|
-
service = module.get(index_1.SMS_SERVICE);
|
|
90
|
-
const result = await service.sendSms({
|
|
91
|
-
to: '+84123456789',
|
|
92
|
-
body: 'Queued SMS',
|
|
93
|
-
mode: 'queue',
|
|
94
|
-
});
|
|
95
|
-
expect(result.success).toBe(true);
|
|
96
|
-
expect(result.jobId).toMatch(/^sms-job-/);
|
|
97
|
-
});
|
|
98
|
-
it('should cancel a pending job by dedupId', async () => {
|
|
99
|
-
module = await testing_1.Test.createTestingModule({
|
|
100
|
-
imports: [
|
|
101
|
-
index_1.SmsModule.forRoot({
|
|
102
|
-
twilio: { accountSid: 'sid', authToken: 'token' },
|
|
103
|
-
queue: {
|
|
104
|
-
useQueue: true,
|
|
105
|
-
connection: { url: 'redis://localhost:6379' },
|
|
106
|
-
worker: false,
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
],
|
|
110
|
-
}).compile();
|
|
111
|
-
await module.init();
|
|
112
|
-
service = module.get(index_1.SMS_SERVICE);
|
|
113
|
-
const sendResult = await service.sendSms({
|
|
114
|
-
to: '+84123456789',
|
|
115
|
-
body: 'Cancel test',
|
|
116
|
-
mode: 'queue',
|
|
117
|
-
dedupId: 'sms-cancel-test',
|
|
118
|
-
});
|
|
119
|
-
expect(sendResult.success).toBe(true);
|
|
120
|
-
await service.cancelJob('sms-cancel-test');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../src/notification/sms/index.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;QACzC,GAAG,EAAE,IAAI;aACN,EAAE,EAAE;aAC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AE,KAAK,IAAI,EAAE;QACtD,MAAM,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YACtC,OAAO,EAAE;gBACP,iBAAS,CAAC,OAAO,CAAC;oBAChB,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE;oBACjD,KAAK,EAAE;wBACL,QAAQ,EAAE,IAAI;wBACd,UAAU,EAAE,EAAE,GAAG,EAAE,wBAAwB,EAAE;wBAC7C,MAAM,EAAE,KAAK;qBACd;iBACF,CAAC;aACH;SACF,CAAC,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAW,CAAC,CAAC;QAElC,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC;YACvC,EAAE,EAAE,cAAc;YAClB,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;QACH,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtC,MAAM,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { DynamicModule, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
|
|
2
|
-
import type { SendMode, SendResult, NotificationStorage, NotificationTemplate } from '../shared';
|
|
3
|
-
export declare const TELEGRAM_SERVICE = "TELEGRAM_SERVICE";
|
|
4
|
-
export interface SendTelegramOptions {
|
|
5
|
-
chatId: string | number;
|
|
6
|
-
text?: string;
|
|
7
|
-
parseMode?: 'HTML' | 'MarkdownV2' | 'Markdown';
|
|
8
|
-
disableWebPagePreview?: boolean;
|
|
9
|
-
disableNotification?: boolean;
|
|
10
|
-
replyToMessageId?: number;
|
|
11
|
-
template?: string;
|
|
12
|
-
context?: Record<string, unknown>;
|
|
13
|
-
locale?: string;
|
|
14
|
-
mode?: SendMode;
|
|
15
|
-
expiresAt?: Date | string;
|
|
16
|
-
dedupId?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ITelegramService {
|
|
19
|
-
sendTelegram(options: SendTelegramOptions): Promise<SendResult>;
|
|
20
|
-
cancelJob(dedupId: string): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export interface TelegramModuleOptions {
|
|
23
|
-
botToken: string;
|
|
24
|
-
defaultLocale?: string;
|
|
25
|
-
queue?: {
|
|
26
|
-
useQueue?: boolean;
|
|
27
|
-
connection?: {
|
|
28
|
-
url: string;
|
|
29
|
-
};
|
|
30
|
-
prefix?: string;
|
|
31
|
-
defaultJobOptions?: Record<string, unknown>;
|
|
32
|
-
worker?: boolean;
|
|
33
|
-
concurrency?: number;
|
|
34
|
-
};
|
|
35
|
-
templates?: {
|
|
36
|
-
dir?: string;
|
|
37
|
-
templates?: Record<string, NotificationTemplate>;
|
|
38
|
-
};
|
|
39
|
-
storage?: {
|
|
40
|
-
provider?: NotificationStorage;
|
|
41
|
-
typeorm?: boolean;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export declare class TelegramModule {
|
|
45
|
-
static forRoot(options: TelegramModuleOptions): DynamicModule;
|
|
46
|
-
static forRootAsync(options: {
|
|
47
|
-
useFactory: (...args: unknown[]) => TelegramModuleOptions | Promise<TelegramModuleOptions>;
|
|
48
|
-
inject?: (InjectionToken | OptionalFactoryDependency)[];
|
|
49
|
-
}): DynamicModule;
|
|
50
|
-
}
|