@solidstarters/solid-core 1.2.156 → 1.2.157

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.
Files changed (126) hide show
  1. package/dist/config/common.config.d.ts +2 -0
  2. package/dist/config/common.config.d.ts.map +1 -1
  3. package/dist/config/common.config.js +1 -0
  4. package/dist/config/common.config.js.map +1 -1
  5. package/dist/decorators/whatsapp-provider.decorator.d.ts +3 -0
  6. package/dist/decorators/whatsapp-provider.decorator.d.ts.map +1 -0
  7. package/dist/decorators/whatsapp-provider.decorator.js +11 -0
  8. package/dist/decorators/whatsapp-provider.decorator.js.map +1 -0
  9. package/dist/factories/whatsapp.factory.d.ts +14 -0
  10. package/dist/factories/whatsapp.factory.d.ts.map +1 -0
  11. package/dist/factories/whatsapp.factory.js +53 -0
  12. package/dist/factories/whatsapp.factory.js.map +1 -0
  13. package/dist/helpers/solid-registry.d.ts +3 -0
  14. package/dist/helpers/solid-registry.d.ts.map +1 -1
  15. package/dist/helpers/solid-registry.js +7 -0
  16. package/dist/helpers/solid-registry.js.map +1 -1
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces.d.ts +3 -0
  22. package/dist/interfaces.d.ts.map +1 -1
  23. package/dist/interfaces.js.map +1 -1
  24. package/dist/jobs/database/{whatsapp-publisher-database.service.d.ts → msg91-whatsapp-publisher-database.service.d.ts} +2 -2
  25. package/dist/jobs/database/msg91-whatsapp-publisher-database.service.d.ts.map +1 -0
  26. package/dist/jobs/database/{whatsapp-publisher-database.service.js → msg91-whatsapp-publisher-database.service.js} +8 -8
  27. package/dist/jobs/database/msg91-whatsapp-publisher-database.service.js.map +1 -0
  28. package/dist/jobs/database/{whatsapp-queue-options-database.d.ts → msg91-whatsapp-queue-options-database.d.ts} +1 -1
  29. package/dist/jobs/database/msg91-whatsapp-queue-options-database.d.ts.map +1 -0
  30. package/dist/jobs/database/{whatsapp-queue-options-database.js → msg91-whatsapp-queue-options-database.js} +2 -2
  31. package/dist/jobs/database/msg91-whatsapp-queue-options-database.js.map +1 -0
  32. package/dist/jobs/database/{whatsapp-subscriber-database.service.d.ts → msg91-whatsapp-subscriber-database.service.d.ts} +2 -2
  33. package/dist/jobs/database/msg91-whatsapp-subscriber-database.service.d.ts.map +1 -0
  34. package/dist/jobs/database/{whatsapp-subscriber-database.service.js → msg91-whatsapp-subscriber-database.service.js} +9 -9
  35. package/dist/jobs/database/msg91-whatsapp-subscriber-database.service.js.map +1 -0
  36. package/dist/jobs/database/three60-whatsapp-publisher-database.service.d.ts +11 -0
  37. package/dist/jobs/database/three60-whatsapp-publisher-database.service.d.ts.map +1 -0
  38. package/dist/jobs/database/three60-whatsapp-publisher-database.service.js +39 -0
  39. package/dist/jobs/database/three60-whatsapp-publisher-database.service.js.map +1 -0
  40. package/dist/jobs/database/three60-whatsapp-queue-options-database.d.ts +8 -0
  41. package/dist/jobs/database/three60-whatsapp-queue-options-database.d.ts.map +1 -0
  42. package/dist/jobs/database/three60-whatsapp-queue-options-database.js +10 -0
  43. package/dist/jobs/database/three60-whatsapp-queue-options-database.js.map +1 -0
  44. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.d.ts +17 -0
  45. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.d.ts.map +1 -0
  46. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.js +48 -0
  47. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.js.map +1 -0
  48. package/dist/jobs/{whatsapp-publisher.service.d.ts → msg91-whatsapp-publisher.service.d.ts} +2 -2
  49. package/dist/jobs/msg91-whatsapp-publisher.service.d.ts.map +1 -0
  50. package/dist/jobs/{whatsapp-publisher.service.js → msg91-whatsapp-publisher.service.js} +8 -8
  51. package/dist/jobs/msg91-whatsapp-publisher.service.js.map +1 -0
  52. package/dist/jobs/{whatsapp-queue-options.d.ts → msg91-whatsapp-queue-options.d.ts} +1 -1
  53. package/dist/jobs/msg91-whatsapp-queue-options.d.ts.map +1 -0
  54. package/dist/jobs/msg91-whatsapp-queue-options.js +10 -0
  55. package/dist/jobs/msg91-whatsapp-queue-options.js.map +1 -0
  56. package/dist/jobs/{whatsapp-subscriber.service.d.ts → msg91-whatsapp-subscriber.service.d.ts} +2 -2
  57. package/dist/jobs/msg91-whatsapp-subscriber.service.d.ts.map +1 -0
  58. package/dist/jobs/{whatsapp-subscriber.service.js → msg91-whatsapp-subscriber.service.js} +9 -9
  59. package/dist/jobs/msg91-whatsapp-subscriber.service.js.map +1 -0
  60. package/dist/jobs/three60-whatsapp-publisher.service.d.ts +11 -0
  61. package/dist/jobs/three60-whatsapp-publisher.service.d.ts.map +1 -0
  62. package/dist/jobs/three60-whatsapp-publisher.service.js +39 -0
  63. package/dist/jobs/three60-whatsapp-publisher.service.js.map +1 -0
  64. package/dist/jobs/three60-whatsapp-queue-options.d.ts +8 -0
  65. package/dist/jobs/three60-whatsapp-queue-options.d.ts.map +1 -0
  66. package/dist/jobs/{whatsapp-queue-options.js → three60-whatsapp-queue-options.js} +3 -3
  67. package/dist/jobs/three60-whatsapp-queue-options.js.map +1 -0
  68. package/dist/jobs/three60-whatsapp-subscriber.service.d.ts +15 -0
  69. package/dist/jobs/three60-whatsapp-subscriber.service.d.ts.map +1 -0
  70. package/dist/jobs/three60-whatsapp-subscriber.service.js +45 -0
  71. package/dist/jobs/three60-whatsapp-subscriber.service.js.map +1 -0
  72. package/dist/services/chatter-message.service.d.ts.map +1 -1
  73. package/dist/services/chatter-message.service.js +6 -0
  74. package/dist/services/chatter-message.service.js.map +1 -1
  75. package/dist/services/solid-introspect.service.d.ts +1 -0
  76. package/dist/services/solid-introspect.service.d.ts.map +1 -1
  77. package/dist/services/solid-introspect.service.js +14 -0
  78. package/dist/services/solid-introspect.service.js.map +1 -1
  79. package/dist/services/whatsapp/Msg91WhatsappService.d.ts +8 -6
  80. package/dist/services/whatsapp/Msg91WhatsappService.d.ts.map +1 -1
  81. package/dist/services/whatsapp/Msg91WhatsappService.js +24 -7
  82. package/dist/services/whatsapp/Msg91WhatsappService.js.map +1 -1
  83. package/dist/services/whatsapp/Three60WhatsappService.d.ts +18 -0
  84. package/dist/services/whatsapp/Three60WhatsappService.d.ts.map +1 -0
  85. package/dist/services/whatsapp/Three60WhatsappService.js +61 -0
  86. package/dist/services/whatsapp/Three60WhatsappService.js.map +1 -0
  87. package/dist/solid-core.module.d.ts.map +1 -1
  88. package/dist/solid-core.module.js +20 -8
  89. package/dist/solid-core.module.js.map +1 -1
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +1 -1
  92. package/src/config/common.config.ts +1 -0
  93. package/src/decorators/whatsapp-provider.decorator.ts +7 -0
  94. package/src/factories/whatsapp.factory.ts +41 -0
  95. package/src/helpers/solid-registry.ts +9 -0
  96. package/src/index.ts +3 -3
  97. package/src/interfaces.ts +12 -2
  98. package/src/jobs/database/{whatsapp-publisher-database.service.ts → msg91-whatsapp-publisher-database.service.ts} +2 -2
  99. package/src/jobs/database/{whatsapp-queue-options-database.ts → msg91-whatsapp-queue-options-database.ts} +1 -1
  100. package/src/jobs/database/{whatsapp-subscriber-database.service.ts → msg91-whatsapp-subscriber-database.service.ts} +3 -4
  101. package/src/jobs/database/three60-whatsapp-publisher-database.service.ts +23 -0
  102. package/src/jobs/database/three60-whatsapp-queue-options-database.ts +9 -0
  103. package/src/jobs/database/three60-whatsapp-subscriber-database.service.ts +32 -0
  104. package/src/jobs/{whatsapp-publisher.service.ts → msg91-whatsapp-publisher.service.ts} +2 -2
  105. package/src/jobs/msg91-whatsapp-queue-options.ts +12 -0
  106. package/src/jobs/{whatsapp-subscriber.service.ts → msg91-whatsapp-subscriber.service.ts} +3 -3
  107. package/src/jobs/three60-whatsapp-publisher.service.ts +23 -0
  108. package/src/jobs/{whatsapp-queue-options.ts → three60-whatsapp-queue-options.ts} +2 -2
  109. package/src/jobs/three60-whatsapp-subscriber.service.ts +30 -0
  110. package/src/services/chatter-message.service.ts +6 -0
  111. package/src/services/solid-introspect.service.ts +22 -0
  112. package/src/services/whatsapp/Msg91WhatsappService.ts +34 -10
  113. package/src/services/whatsapp/Three60WhatsappService.ts +52 -0
  114. package/src/solid-core.module.ts +20 -8
  115. package/dist/jobs/database/whatsapp-publisher-database.service.d.ts.map +0 -1
  116. package/dist/jobs/database/whatsapp-publisher-database.service.js.map +0 -1
  117. package/dist/jobs/database/whatsapp-queue-options-database.d.ts.map +0 -1
  118. package/dist/jobs/database/whatsapp-queue-options-database.js.map +0 -1
  119. package/dist/jobs/database/whatsapp-subscriber-database.service.d.ts.map +0 -1
  120. package/dist/jobs/database/whatsapp-subscriber-database.service.js.map +0 -1
  121. package/dist/jobs/whatsapp-publisher.service.d.ts.map +0 -1
  122. package/dist/jobs/whatsapp-publisher.service.js.map +0 -1
  123. package/dist/jobs/whatsapp-queue-options.d.ts.map +0 -1
  124. package/dist/jobs/whatsapp-queue-options.js.map +0 -1
  125. package/dist/jobs/whatsapp-subscriber.service.d.ts.map +0 -1
  126. package/dist/jobs/whatsapp-subscriber.service.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.156",
3
+ "version": "1.2.157",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,6 +3,7 @@ import { registerAs } from '@nestjs/config';
3
3
  export default registerAs('common', () => {
4
4
  return {
5
5
  emailProvider: process.env.COMMON_EMAIL_PROVIDER ?? "SMTPEMailService",
6
+ whatsappProvider: process.env.COMMON_WHATSAPP_PROVIDER,
6
7
  emailTemplateSeederFiles: process.env.COMMON_EMAIL_TEMPLATE_SEEDER_FILES,
7
8
  smsProvider: process.env.COMMON_SMS_PROVIDER,
8
9
  smsTemplateSeederFiles: process.env.COMMON_SMS_TEMPLATE_SEEDER_FILES,
@@ -0,0 +1,7 @@
1
+ export const IS_WA_PROVIDER = 'IS_WA_PROVIDER';
2
+
3
+ export const WhatsAppProvider = () => {
4
+ return (target: Function) => {
5
+ Reflect.defineMetadata(IS_WA_PROVIDER, true, target);
6
+ };
7
+ };
@@ -0,0 +1,41 @@
1
+ import { Inject, Injectable, Logger } from "@nestjs/common";
2
+ import { ConfigType } from "@nestjs/config";
3
+ import { ModuleRef } from "@nestjs/core";
4
+ import commonConfig from "src/config/common.config";
5
+ import { SolidRegistry } from "src/helpers/solid-registry";
6
+ import { IWhatsAppTransport } from "src/interfaces";
7
+
8
+ function norm(s?: string) {
9
+ return s?.trim().toLowerCase();
10
+ }
11
+
12
+ // This factory will be use to return a mail service instance, using the configured environment variables
13
+ @Injectable()
14
+ export class WhatsAppFactory {
15
+ private readonly logger = new Logger(this.constructor.name);
16
+ constructor(
17
+ private readonly moduleRef: ModuleRef, // Use the module ref to dynamically resolve the mail service
18
+ private readonly solidRegistry: SolidRegistry,
19
+ @Inject(commonConfig.KEY)
20
+ private readonly commonConfiguration: ConfigType<typeof commonConfig>,
21
+ ) { }
22
+
23
+ getWhatsappService(name: string = null): IWhatsAppTransport {
24
+ // This is the default provider
25
+ const whatsappServiceName = this.commonConfiguration.whatsappProvider || name;
26
+ if (!whatsappServiceName) {
27
+ throw new Error("Unable to resolve whatsapp provider")
28
+ }
29
+ const whatsappProviders = this.solidRegistry.getWhatsappProviders();
30
+ // Return the instance which matches the whatsappServiceName
31
+ if (!whatsappProviders.length) {
32
+ // throw new Error("No mail providers are registered.");
33
+ this.logger.error("No whatsapp providers are registered.");
34
+ }
35
+
36
+ const whatsappServiceProvider = whatsappProviders.find(provider => provider.name === whatsappServiceName);
37
+
38
+ return whatsappServiceProvider.instance as IWhatsAppTransport;
39
+ }
40
+
41
+ }
@@ -66,6 +66,11 @@ export class SolidRegistry {
66
66
  private dashboardVariableSelectionProviders: Set<InstanceWrapper> = new Set();
67
67
  private dashboardQuestionDataProviders: Set<InstanceWrapper> = new Set();
68
68
  private mailProviders: Set<InstanceWrapper> = new Set();
69
+ private whatsappProviders: Set<InstanceWrapper> = new Set();
70
+
71
+ registerWhatsappProvider(whatsappProvider: InstanceWrapper): void {
72
+ this.whatsappProviders.add(whatsappProvider);
73
+ }
69
74
 
70
75
  registerMailProvider(mailProvider: InstanceWrapper): void {
71
76
  this.mailProviders.add(mailProvider);
@@ -115,6 +120,10 @@ export class SolidRegistry {
115
120
  return Array.from(this.mailProviders);
116
121
  }
117
122
 
123
+ getWhatsappProviders(): Array<InstanceWrapper> {
124
+ return Array.from(this.whatsappProviders);
125
+ }
126
+
118
127
  getSeeders(): Array<InstanceWrapper> {
119
128
  return Array.from(this.seeders);
120
129
  }
package/src/index.ts CHANGED
@@ -193,9 +193,9 @@ export * from './jobs/otp-subscriber.service'
193
193
  export * from './jobs/sms-publisher.service'
194
194
  export * from './jobs/sms-queue-options'
195
195
  export * from './jobs/sms-subscriber.service'
196
- export * from './jobs/whatsapp-publisher.service'
197
- export * from './jobs/whatsapp-queue-options'
198
- export * from './jobs/whatsapp-subscriber.service'
196
+ export * from './jobs/msg91-whatsapp-publisher.service'
197
+ export * from './jobs/msg91-whatsapp-queue-options'
198
+ export * from './jobs/msg91-whatsapp-subscriber.service'
199
199
 
200
200
  export * from './listeners/user-registration.listener'
201
201
 
package/src/interfaces.ts CHANGED
@@ -134,7 +134,7 @@ export interface IEntityComputedFieldProvider {
134
134
  name(): string;
135
135
  }
136
136
 
137
- export interface IEntityPreComputeFieldProvider<TTriggerEntity, TContext, TValue=void> extends IEntityComputedFieldProvider {
137
+ export interface IEntityPreComputeFieldProvider<TTriggerEntity, TContext, TValue = void> extends IEntityComputedFieldProvider {
138
138
  preComputeValue(triggerEntity: TTriggerEntity, computedFieldMetadata: ComputedFieldMetadata<TContext>): Promise<TValue>;
139
139
  }
140
140
 
@@ -159,7 +159,7 @@ export class EventDetails<T> {
159
159
  ) { }
160
160
  }
161
161
 
162
- export interface IMail<TResponse=unknown> {
162
+ export interface IMail<TResponse = unknown> {
163
163
  sendEmail(
164
164
  to: string,
165
165
  subject: string,
@@ -200,6 +200,16 @@ export interface ISMS {
200
200
  ): Promise<any>;
201
201
  }
202
202
 
203
+ export interface IWhatsAppTransport {
204
+ sendWhatsAppMessage(
205
+ to: string,
206
+ templateId: string,
207
+ parameters: any,
208
+ parentEntity?: any,
209
+ parentEntityId?: any
210
+ ): Promise<any>;
211
+ }
212
+
203
213
  export interface MailAttachmentWrapper {
204
214
  relativePath?: string;
205
215
  attachment?: MailAttachment;
@@ -1,13 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
- import whatsappQueueOptions from './whatsapp-queue-options-database';
3
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options-database';
4
4
  import { MqMessageService } from 'src/services/mq-message.service';
5
5
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
6
6
  import { QueuesModuleOptions } from 'src/interfaces';
7
7
  import { DatabasePublisher } from 'src/services/queues/database-publisher.service';
8
8
 
9
9
  @Injectable()
10
- export class WhatsappQueuePublisherDatabase extends DatabasePublisher<any> {
10
+ export class Msg91WhatsappQueuePublisherDatabase extends DatabasePublisher<any> {
11
11
  constructor(
12
12
  protected readonly mqMessageService: MqMessageService,
13
13
  protected readonly mqMessageQueueService: MqMessageQueueService,
@@ -1,6 +1,6 @@
1
1
  import { BrokerType } from "src/interfaces";
2
2
 
3
- const WHATSAPP_QUEUE_NAME = 'whatsapp_queue_database';
3
+ const WHATSAPP_QUEUE_NAME = 'msg91_whatsapp_queue_database';
4
4
 
5
5
  export default {
6
6
  name: 'whatsappInstance',
@@ -1,8 +1,7 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
- import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
4
3
  import { QueueMessage } from 'src/interfaces/mq';
5
- import whatsappQueueOptions from './whatsapp-queue-options-database';
4
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options-database';
6
5
  import { MqMessageService } from 'src/services/mq-message.service';
7
6
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
8
7
  import { Msg91WhatsappService } from 'src/services/whatsapp/Msg91WhatsappService';
@@ -11,7 +10,7 @@ import { DatabaseSubscriber } from 'src/services/queues/database-subscriber.serv
11
10
  import { PollerService } from 'src/services/poller.service';
12
11
 
13
12
  @Injectable()
14
- export class WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {
13
+ export class Msg91WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {
15
14
  constructor(
16
15
  private readonly whatsappService: Msg91WhatsappService,
17
16
  readonly mqMessageService: MqMessageService,
@@ -28,6 +27,6 @@ export class WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {
28
27
  }
29
28
 
30
29
  subscribe(message: QueueMessage<any>) {
31
- this.whatsappService.sendSMSSynchronously(message);
30
+ this.whatsappService.sendWhatsAppMessageSynchronously(message);
32
31
  }
33
32
  }
@@ -0,0 +1,23 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options-database';
4
+ import { MqMessageService } from 'src/services/mq-message.service';
5
+ import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
6
+ import { QueuesModuleOptions } from 'src/interfaces';
7
+ import { DatabasePublisher } from 'src/services/queues/database-publisher.service';
8
+
9
+ @Injectable()
10
+ export class Three60WhatsappQueuePublisherDatabase extends DatabasePublisher<any> {
11
+ constructor(
12
+ protected readonly mqMessageService: MqMessageService,
13
+ protected readonly mqMessageQueueService: MqMessageQueueService,
14
+ ) {
15
+ super(mqMessageService, mqMessageQueueService);
16
+ }
17
+
18
+ options(): QueuesModuleOptions {
19
+ return {
20
+ ...whatsappQueueOptions
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ import { BrokerType } from "src/interfaces";
2
+
3
+ const WHATSAPP_QUEUE_NAME = 'three60_whatsapp_queue_database';
4
+
5
+ export default {
6
+ name: 'whatsappInstance',
7
+ type: BrokerType.Database,
8
+ queueName: WHATSAPP_QUEUE_NAME,
9
+ };
@@ -0,0 +1,32 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { QueueMessage } from 'src/interfaces/mq';
4
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options-database';
5
+ import { MqMessageService } from 'src/services/mq-message.service';
6
+ import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
7
+ import { QueuesModuleOptions } from 'src/interfaces';
8
+ import { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';
9
+ import { PollerService } from 'src/services/poller.service';
10
+ import { Three60WhatsappService } from 'src/services/whatsapp/Three60WhatsappService';
11
+
12
+ @Injectable()
13
+ export class Three60WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {
14
+ constructor(
15
+ private readonly whatsappService: Three60WhatsappService,
16
+ readonly mqMessageService: MqMessageService,
17
+ readonly mqMessageQueueService: MqMessageQueueService,
18
+ readonly poller: PollerService,
19
+ ) {
20
+ super(mqMessageService, mqMessageQueueService, poller);
21
+ }
22
+
23
+ options(): QueuesModuleOptions {
24
+ return {
25
+ ...whatsappQueueOptions
26
+ }
27
+ }
28
+
29
+ subscribe(message: QueueMessage<any>) {
30
+ this.whatsappService.sendWhatsAppMessageSynchronously(message);
31
+ }
32
+ }
@@ -1,13 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
 
3
3
  import { RabbitMqPublisher } from 'src/services/queues/rabbitmq-publisher.service';
4
- import whatsappQueueOptions from './whatsapp-queue-options';
4
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options';
5
5
  import { MqMessageService } from 'src/services/mq-message.service';
6
6
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
7
7
  import { QueuesModuleOptions } from "../interfaces";
8
8
 
9
9
  @Injectable()
10
- export class WhatsappQueuePublisher extends RabbitMqPublisher<any> {
10
+ export class Msg91WhatsappQueuePublisher extends RabbitMqPublisher<any> {
11
11
  constructor(
12
12
  protected readonly mqMessageService: MqMessageService,
13
13
  protected readonly mqMessageQueueService: MqMessageQueueService,
@@ -0,0 +1,12 @@
1
+ import { BrokerType } from "../interfaces";
2
+
3
+ const MSG91_WHATSAPP_QUEUE_NAME = 'mag_91_whatsapp_queue';
4
+ export default {
5
+ name: 'whatsappInstance',
6
+ type: BrokerType.RabbitMQ,
7
+ queueName: MSG91_WHATSAPP_QUEUE_NAME,
8
+ // receive: async (message: QueueMessage<any>) => { // Default receive handler
9
+ // console.log(`Received message: ${JSON.stringify(message)} from queue ${SMS_QUEUE_NAME}`);
10
+ // return 'Received';
11
+ // },
12
+ };
@@ -2,14 +2,14 @@ import { Injectable } from '@nestjs/common';
2
2
 
3
3
  import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
4
4
  import { QueueMessage } from 'src/interfaces/mq';
5
- import whatsappQueueOptions from './whatsapp-queue-options';
5
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options';
6
6
  import { Msg91WhatsappService } from '../services/whatsapp/Msg91WhatsappService';
7
7
  import { MqMessageService } from 'src/services/mq-message.service';
8
8
  import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
9
9
  import { QueuesModuleOptions } from "../interfaces";
10
10
 
11
11
  @Injectable()
12
- export class WhatsappQueueSubscriber extends RabbitMqSubscriber<any> {
12
+ export class Msg91WhatsappQueueSubscriber extends RabbitMqSubscriber<any> {
13
13
  constructor(
14
14
  private readonly whatsappService: Msg91WhatsappService,
15
15
  readonly mqMessageService: MqMessageService,
@@ -25,6 +25,6 @@ export class WhatsappQueueSubscriber extends RabbitMqSubscriber<any> {
25
25
  }
26
26
 
27
27
  subscribe(message: QueueMessage<any>) {
28
- this.whatsappService.sendSMSSynchronously(message);
28
+ this.whatsappService.sendWhatsAppMessageSynchronously(message);
29
29
  }
30
30
  }
@@ -0,0 +1,23 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { RabbitMqPublisher } from 'src/services/queues/rabbitmq-publisher.service';
4
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options';
5
+ import { MqMessageService } from 'src/services/mq-message.service';
6
+ import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
7
+ import { QueuesModuleOptions } from "../interfaces";
8
+
9
+ @Injectable()
10
+ export class Three60WhatsappQueuePublisher extends RabbitMqPublisher<any> {
11
+ constructor(
12
+ protected readonly mqMessageService: MqMessageService,
13
+ protected readonly mqMessageQueueService: MqMessageQueueService,
14
+ ) {
15
+ super(mqMessageService, mqMessageQueueService);
16
+ }
17
+
18
+ options(): QueuesModuleOptions {
19
+ return {
20
+ ...whatsappQueueOptions
21
+ }
22
+ }
23
+ }
@@ -1,10 +1,10 @@
1
1
  import { BrokerType } from "../interfaces";
2
2
 
3
- const WHATSAPP_QUEUE_NAME = 'whatsapp_queue';
3
+ const _WHATSAPP_QUEUE_NAME = 'three60_whatsapp_queue';
4
4
  export default {
5
5
  name: 'whatsappInstance',
6
6
  type: BrokerType.RabbitMQ,
7
- queueName: WHATSAPP_QUEUE_NAME,
7
+ queueName: _WHATSAPP_QUEUE_NAME,
8
8
  // receive: async (message: QueueMessage<any>) => { // Default receive handler
9
9
  // console.log(`Received message: ${JSON.stringify(message)} from queue ${SMS_QUEUE_NAME}`);
10
10
  // return 'Received';
@@ -0,0 +1,30 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { RabbitMqSubscriber } from 'src/services/queues/rabbitmq-subscriber.service';
4
+ import { QueueMessage } from 'src/interfaces/mq';
5
+ import whatsappQueueOptions from './msg91-whatsapp-queue-options';
6
+ import { MqMessageService } from 'src/services/mq-message.service';
7
+ import { MqMessageQueueService } from 'src/services/mq-message-queue.service';
8
+ import { QueuesModuleOptions } from "../interfaces";
9
+ import { Three60WhatsappService } from 'src/services/whatsapp/Three60WhatsappService';
10
+
11
+ @Injectable()
12
+ export class Three60WhatsappQueueSubscriber extends RabbitMqSubscriber<any> {
13
+ constructor(
14
+ private readonly whatsappService: Three60WhatsappService,
15
+ readonly mqMessageService: MqMessageService,
16
+ readonly mqMessageQueueService: MqMessageQueueService,
17
+ ) {
18
+ super(mqMessageService, mqMessageQueueService);
19
+ }
20
+
21
+ options(): QueuesModuleOptions {
22
+ return {
23
+ ...whatsappQueueOptions
24
+ }
25
+ }
26
+
27
+ subscribe(message: QueueMessage<any>) {
28
+ this.whatsappService.sendWhatsAppMessageSynchronously(message);
29
+ }
30
+ }
@@ -86,6 +86,9 @@ export class ChatterMessageService extends CRUDService<ChatterMessage>{
86
86
  }
87
87
 
88
88
  async postAuditMessageOnInsert(entity: any, metadata: EntityMetadata, messageQueue: boolean = false) {
89
+ if(!entity){
90
+ return;
91
+ }
89
92
  const model = await this.modelMetadataRepo.findOne({
90
93
  where: {
91
94
  displayName: metadata.name
@@ -140,6 +143,9 @@ export class ChatterMessageService extends CRUDService<ChatterMessage>{
140
143
  }
141
144
 
142
145
  async postAuditMessageOnUpdate(entity: any, metadata: EntityMetadata, databaseEntity: any, messageQueue: boolean = false) {
146
+ if(!databaseEntity || !entity){
147
+ return;
148
+ }
143
149
  const model = await this.modelMetadataRepo.findOne({
144
150
  where: {
145
151
  displayName: metadata.name
@@ -11,6 +11,7 @@ import { IS_SCHEDULED_JOB_PROVIDER } from 'src/decorators/scheduled-job-provider
11
11
  import { IS_DASHBOARD_VARIABLE_SELECTION_PROVIDER } from 'src/decorators/dashboard-selection-provider.decorator';
12
12
  import { IS_DASHBOARD_QUESTION_DATA_PROVIDER } from 'src/decorators/dashboard-question-data-provider.decorator';
13
13
  import { IS_MAIL_PROVIDER } from 'src/decorators/mail-provider.decorator';
14
+ import { IS_WA_PROVIDER } from 'src/decorators/whatsapp-provider.decorator';
14
15
 
15
16
  @Injectable()
16
17
  export class SolidIntrospectService implements OnApplicationBootstrap {
@@ -118,6 +119,15 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
118
119
  mailProviders.forEach((mailProvider) => {
119
120
  this.solidRegistry.registerMailProvider(mailProvider);
120
121
  });
122
+
123
+ // Register all IMail implementations
124
+ const whatsappProviders = this.discoveryService
125
+ .getProviders()
126
+ .filter((provider) => this.isWhatsappProvider(provider));
127
+
128
+ whatsappProviders.forEach((whatsappProvider) => {
129
+ this.solidRegistry.registerWhatsappProvider(whatsappProvider);
130
+ });
121
131
  }
122
132
 
123
133
  isDashboardQuestionDataProvider(providerWrapper: InstanceWrapper<any>) {
@@ -212,6 +222,18 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
212
222
  return !!isMailProvider;
213
223
  }
214
224
 
225
+ private isWhatsappProvider(provider: InstanceWrapper) {
226
+ const { instance } = provider;
227
+ if (!instance) return false;
228
+
229
+ const isWhatsappProvider = this.reflector.get<boolean>(
230
+ IS_WA_PROVIDER,
231
+ instance.constructor,
232
+ );
233
+
234
+ return !!isWhatsappProvider;
235
+ }
236
+
215
237
  private isModule(provider: InstanceWrapper): boolean {
216
238
  const metatype = provider.metatype;
217
239
  // Check if it's a Static Module (Class-Based)
@@ -3,10 +3,9 @@ import { Inject, Injectable, Logger } from '@nestjs/common';
3
3
  import { ConfigType } from '@nestjs/config';
4
4
  import commonConfig from 'src/config/common.config';
5
5
  import { QueueMessage } from 'src/interfaces/mq';
6
- import { SmsTemplateService } from '../sms-template.service';
7
- import { Msg91BaseSMSService } from '../sms/Msg91BaseSMSService';
8
- import { ISMS } from "../../interfaces";
6
+ import { IWhatsAppTransport } from "../../interfaces";
9
7
  import { PublisherFactory } from '../queues/publisher-factory.service';
8
+ import { WhatsAppProvider } from 'src/decorators/whatsapp-provider.decorator';
10
9
 
11
10
  enum Msg91WhatsappParameterHeaderType {
12
11
  image,
@@ -51,21 +50,46 @@ interface WhatsappToAndComponents {
51
50
  }
52
51
 
53
52
  @Injectable()
54
- export class Msg91WhatsappService extends Msg91BaseSMSService implements ISMS {
53
+ @WhatsAppProvider()
54
+ export class Msg91WhatsappService implements IWhatsAppTransport {
55
55
  readonly logger = new Logger(Msg91WhatsappService.name);
56
56
 
57
57
  constructor(
58
58
  @Inject(commonConfig.KEY)
59
- commonConfiguration: ConfigType<typeof commonConfig>,
59
+ private readonly commonConfiguration: ConfigType<typeof commonConfig>,
60
60
  // whatsappPublisher: WhatsappQueuePublisher,
61
- publisherFactory: PublisherFactory<any>,
62
- smsTemplateService: SmsTemplateService,
61
+ private readonly publisherFactory: PublisherFactory<any>,
63
62
  private readonly httpService: HttpService,
64
- ) {
65
- super(commonConfiguration, 'WhatsappQueuePublisher', publisherFactory, smsTemplateService);
63
+ ) {}
64
+
65
+ async sendWhatsAppMessage(
66
+ to: string,
67
+ templateId: string,
68
+ parameters: any,
69
+ parentEntity?: any,
70
+ parentEntityId?: any
71
+ ): Promise<any> {
72
+ const message = {
73
+ payload: {
74
+ to,
75
+ templateId,
76
+ ...parameters,
77
+ },
78
+ parentEntity,
79
+ parentEntityId,
80
+ };
81
+
82
+ // All messages are always queued as per requirement
83
+ return this.sendWhatsAppMessageAsynchronously(message);
84
+ }
85
+
86
+ private async sendWhatsAppMessageAsynchronously(message: any): Promise<any> {
87
+ const { to, templateId } = message.payload;
88
+ this.logger.debug(`Queueing WhatsApp message to ${to} with template ${templateId}`);
89
+ return this.publisherFactory.publish(message, 'Msg91WhatsappQueuePublisher');
66
90
  }
67
91
 
68
- async sendSMSSynchronously(message: QueueMessage<any>): Promise<void> {
92
+ async sendWhatsAppMessageSynchronously(message: QueueMessage<any>): Promise<void> {
69
93
  const body = this.createWhatsappRequest(message);
70
94
  const headers = { authkey: this.commonConfiguration.msg91Whatsapp.apiKey };
71
95
  await this.httpService.axiosRef.post(
@@ -0,0 +1,52 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import { Inject, Injectable, Logger } from '@nestjs/common';
3
+ import { ConfigType } from '@nestjs/config';
4
+ import commonConfig from 'src/config/common.config';
5
+ import { QueueMessage } from 'src/interfaces/mq';
6
+ import { IWhatsAppTransport } from "../../interfaces";
7
+ import { PublisherFactory } from '../queues/publisher-factory.service';
8
+ import { WhatsAppProvider } from 'src/decorators/whatsapp-provider.decorator';
9
+
10
+ @Injectable()
11
+ @WhatsAppProvider()
12
+ export class Three60WhatsappService implements IWhatsAppTransport {
13
+ readonly logger = new Logger(Three60WhatsappService.name);
14
+
15
+ constructor(
16
+ @Inject(commonConfig.KEY)
17
+ private readonly commonConfiguration: ConfigType<typeof commonConfig>,
18
+ private readonly publisherFactory: PublisherFactory<any>,
19
+ private readonly httpService: HttpService,
20
+ ) { }
21
+
22
+ async sendWhatsAppMessage(
23
+ to: string,
24
+ templateId: string,
25
+ parameters: any,
26
+ parentEntity?: any,
27
+ parentEntityId?: any
28
+ ): Promise<any> {
29
+ const message = {
30
+ payload: {
31
+ to,
32
+ templateId,
33
+ ...parameters,
34
+ },
35
+ parentEntity,
36
+ parentEntityId,
37
+ };
38
+
39
+ // All messages are always queued as per requirement
40
+ return this.sendWhatsAppMessageAsynchronously(message);
41
+ }
42
+
43
+ private async sendWhatsAppMessageAsynchronously(message: any): Promise<any> {
44
+ const { to, templateId } = message.payload;
45
+ this.logger.debug(`Queueing WhatsApp message to ${to} with template ${templateId}`);
46
+ return this.publisherFactory.publish(message, 'Three60WhatsappQueuePublisher');
47
+ }
48
+
49
+ async sendWhatsAppMessageSynchronously(message: QueueMessage<any>): Promise<void> {
50
+ throw new Error(`Currently not implemented.`);
51
+ }
52
+ }
@@ -94,8 +94,8 @@ import { SmsQueuePublisher } from './jobs/sms-publisher.service';
94
94
  import { SmsQueueSubscriber } from './jobs/sms-subscriber.service';
95
95
  import { TestQueuePublisher } from './jobs/test-queue-publisher.service';
96
96
  import { TestQueueSubscriber } from './jobs/test-queue-subscriber.service';
97
- import { WhatsappQueuePublisher } from './jobs/whatsapp-publisher.service';
98
- import { WhatsappQueueSubscriber } from './jobs/whatsapp-subscriber.service';
97
+ import { Msg91WhatsappQueuePublisher } from './jobs/msg91-whatsapp-publisher.service';
98
+ import { Msg91WhatsappQueueSubscriber } from './jobs/msg91-whatsapp-subscriber.service';
99
99
  import { UserRegistrationListener } from './listeners/user-registration.listener';
100
100
  import { GoogleOauthStrategy } from './passport-strategies/google-oauth.strategy';
101
101
  import { LocalStrategy } from './passport-strategies/local.strategy';
@@ -193,8 +193,8 @@ import { TwilioSmsQueueSubscriberDatabase } from './jobs/database/twilio-sms-sub
193
193
 
194
194
  import { TriggerMcpClientPublisherDatabase } from './jobs/database/trigger-mcp-client-publisher-database.service';
195
195
  import { TriggerMcpClientSubscriberDatabase } from './jobs/database/trigger-mcp-client-subscriber-database.service';
196
- import { WhatsappQueuePublisherDatabase } from './jobs/database/whatsapp-publisher-database.service';
197
- import { WhatsappQueueSubscriberDatabase } from './jobs/database/whatsapp-subscriber-database.service';
196
+ import { Msg91WhatsappQueuePublisherDatabase } from './jobs/database/msg91-whatsapp-publisher-database.service';
197
+ import { Msg91WhatsappQueueSubscriberDatabase } from './jobs/database/msg91-whatsapp-subscriber-database.service';
198
198
  import { DashboardMapper } from './mappers/dashboard-mapper';
199
199
  import { DashboardRepository } from './repository/dashboard.repository';
200
200
  import { FieldMetadataRepository } from './repository/field-metadata.repository';
@@ -276,6 +276,11 @@ import { TextractService } from './services/textract.service';
276
276
  import { seconds, ThrottlerModule } from '@nestjs/throttler';
277
277
  import { ChatterMessageRepository } from './repository/chatter-message.repository';
278
278
  import { ChatterMessageDetailsRepository } from './repository/chatter-message-details.repository';
279
+ import { Three60WhatsappQueuePublisher } from './jobs/three60-whatsapp-publisher.service';
280
+ import { Three60WhatsappQueueSubscriber } from './jobs/three60-whatsapp-subscriber.service';
281
+ import { Three60WhatsappQueuePublisherDatabase } from './jobs/database/three60-whatsapp-publisher-database.service';
282
+ import { Three60WhatsappQueueSubscriberDatabase } from './jobs/database/three60-whatsapp-subscriber-database.service';
283
+ import { Three60WhatsappService } from './services/whatsapp/Three60WhatsappService';
279
284
 
280
285
 
281
286
  @Global()
@@ -492,10 +497,17 @@ import { ChatterMessageDetailsRepository } from './repository/chatter-message-de
492
497
  OTPQueueSubscriber,
493
498
  OTPQueuePublisherDatabase,
494
499
  OTPQueueSubscriberDatabase,
495
- WhatsappQueuePublisher,
496
- WhatsappQueueSubscriber,
497
- WhatsappQueuePublisherDatabase,
498
- WhatsappQueueSubscriberDatabase,
500
+ Msg91WhatsappQueuePublisher,
501
+ Msg91WhatsappQueueSubscriber,
502
+ Msg91WhatsappQueuePublisherDatabase,
503
+ Msg91WhatsappQueueSubscriberDatabase,
504
+ Three60WhatsappQueuePublisher,
505
+ Three60WhatsappQueueSubscriber,
506
+ Three60WhatsappQueuePublisherDatabase,
507
+ Three60WhatsappQueueSubscriberDatabase,
508
+ Three60WhatsappService,
509
+ MqMessageService,
510
+ MqMessageQueueService,
499
511
  EmailTemplateSeederService,
500
512
  SmsTemplateSeederService,
501
513
  TinyUrlService,
@@ -1 +0,0 @@
1
- {"version":3,"file":"whatsapp-publisher-database.service.d.ts","sourceRoot":"","sources":["../../../src/jobs/database/whatsapp-publisher-database.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAEnF,qBACa,8BAA+B,SAAQ,iBAAiB,CAAC,GAAG,CAAC;IAElE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IACrD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;gBAD5C,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,qBAAqB;IAKnE,OAAO,IAAI,mBAAmB;CAKjC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"whatsapp-publisher-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/whatsapp-publisher-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,wGAAqE;AACrE,0EAAmE;AACnE,sFAA8E;AAE9E,iGAAmF;AAG5E,IAAM,8BAA8B,GAApC,MAAM,8BAA+B,SAAQ,8CAAsB;IACtE,YACuB,gBAAkC,EAClC,qBAA4C;QAE/D,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAAC;QAH5B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;IAGnE,CAAC;IAED,OAAO;QACH,OAAO;YACH,GAAG,yCAAoB;SAC1B,CAAA;IACL,CAAC;CACJ,CAAA;AAbY,wEAA8B;yCAA9B,8BAA8B;IAD1C,IAAA,mBAAU,GAAE;qCAGgC,qCAAgB;QACX,gDAAqB;GAH1D,8BAA8B,CAa1C","sourcesContent":["import { Injectable } from '@nestjs/common';\n\nimport whatsappQueueOptions from './whatsapp-queue-options-database';\nimport { MqMessageService } from 'src/services/mq-message.service';\nimport { MqMessageQueueService } from 'src/services/mq-message-queue.service';\nimport { QueuesModuleOptions } from 'src/interfaces';\nimport { DatabasePublisher } from 'src/services/queues/database-publisher.service';\n\n@Injectable()\nexport class WhatsappQueuePublisherDatabase extends DatabasePublisher<any> {\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n ) {\n super(mqMessageService, mqMessageQueueService);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...whatsappQueueOptions\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"whatsapp-queue-options-database.d.ts","sourceRoot":"","sources":["../../../src/jobs/database/whatsapp-queue-options-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;;;;;;AAI5C,wBAIE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"whatsapp-queue-options-database.js","sourceRoot":"","sources":["../../../src/jobs/database/whatsapp-queue-options-database.ts"],"names":[],"mappings":";;AAAA,iDAA4C;AAE5C,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAEtD,kBAAe;IACX,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,uBAAU,CAAC,QAAQ;IACzB,SAAS,EAAE,mBAAmB;CACjC,CAAC","sourcesContent":["import { BrokerType } from \"src/interfaces\";\n\nconst WHATSAPP_QUEUE_NAME = 'whatsapp_queue_database';\n\nexport default {\n name: 'whatsappInstance',\n type: BrokerType.Database,\n queueName: WHATSAPP_QUEUE_NAME,\n};"]}