nest-whatsapp 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +74 -0
- package/README.md +382 -0
- package/dist/cjs/controllers/whatsapp.controller.js +139 -0
- package/dist/cjs/exceptions/whatsapp.exceptions.js +23 -0
- package/dist/cjs/health/whatsapp.health.js +108 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/interfaces/events.js +18 -0
- package/dist/cjs/interfaces/webhook.interfaces.js +3 -0
- package/dist/cjs/interfaces/whatsapp-client-options.interface.js +3 -0
- package/dist/cjs/interfaces/whatsapp-microservice-options.interface.js +3 -0
- package/dist/cjs/interfaces/whatsapp-runtime-options.interface.js +5 -0
- package/dist/cjs/services/whatsapp.events.js +157 -0
- package/dist/cjs/services/whatsapp.metrics.js +100 -0
- package/dist/cjs/services/whatsapp.service.js +382 -0
- package/dist/cjs/services/whatsapp.webhook-processor.js +101 -0
- package/dist/cjs/test-utils/http-helpers.js +7 -0
- package/dist/cjs/test-utils/type-helpers.js +7 -0
- package/dist/cjs/utils/webhook.js +110 -0
- package/dist/cjs/whatsapp.module.js +173 -0
- package/dist/esm/controllers/whatsapp.controller.d.ts +15 -0
- package/dist/esm/controllers/whatsapp.controller.js +103 -0
- package/dist/esm/exceptions/whatsapp.exceptions.d.ts +11 -0
- package/dist/esm/exceptions/whatsapp.exceptions.js +17 -0
- package/dist/esm/health/whatsapp.health.d.ts +22 -0
- package/dist/esm/health/whatsapp.health.js +105 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/interfaces/events.d.ts +46 -0
- package/dist/esm/interfaces/events.js +15 -0
- package/dist/esm/interfaces/webhook.interfaces.d.ts +225 -0
- package/dist/esm/interfaces/webhook.interfaces.js +2 -0
- package/dist/esm/interfaces/whatsapp-client-options.interface.d.ts +18 -0
- package/dist/esm/interfaces/whatsapp-client-options.interface.js +2 -0
- package/dist/esm/interfaces/whatsapp-microservice-options.interface.d.ts +6 -0
- package/dist/esm/interfaces/whatsapp-microservice-options.interface.js +2 -0
- package/dist/esm/interfaces/whatsapp-runtime-options.interface.d.ts +10 -0
- package/dist/esm/interfaces/whatsapp-runtime-options.interface.js +2 -0
- package/dist/esm/services/whatsapp.events.d.ts +56 -0
- package/dist/esm/services/whatsapp.events.js +154 -0
- package/dist/esm/services/whatsapp.metrics.d.ts +17 -0
- package/dist/esm/services/whatsapp.metrics.js +97 -0
- package/dist/esm/services/whatsapp.service.d.ts +40 -0
- package/dist/esm/services/whatsapp.service.js +379 -0
- package/dist/esm/services/whatsapp.webhook-processor.d.ts +11 -0
- package/dist/esm/services/whatsapp.webhook-processor.js +98 -0
- package/dist/esm/test-utils/http-helpers.d.ts +5 -0
- package/dist/esm/test-utils/http-helpers.js +4 -0
- package/dist/esm/test-utils/type-helpers.d.ts +2 -0
- package/dist/esm/test-utils/type-helpers.js +4 -0
- package/dist/esm/utils/webhook.d.ts +63 -0
- package/dist/esm/utils/webhook.js +84 -0
- package/dist/esm/whatsapp.module.d.ts +17 -0
- package/dist/esm/whatsapp.module.js +169 -0
- package/package.json +148 -0
- package/schematics/dist/whatsapp/index.d.ts +17 -0
- package/schematics/dist/whatsapp/index.js +126 -0
- package/schematics/dist/whatsapp/index.spec.d.ts +1 -0
- package/schematics/dist/whatsapp/index.spec.js +88 -0
- package/schematics/whatsapp/collection.json +9 -0
- package/schematics/whatsapp/files/__name__.extend.part +1 -0
- package/schematics/whatsapp/schema.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright [yyyy] [name of copyright owner]
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
|
74
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
# nest-whatsapp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/nest-whatsapp)
|
|
4
|
+
[](https://github.com/SoftZenIT/nest-whatsapp/actions)
|
|
5
|
+
[](https://coveralls.io/github/SoftZenIT/nest-whatsapp?branch=main)
|
|
6
|
+
[](https://SoftZenIT.github.io/nest-whatsapp/)
|
|
7
|
+
|
|
8
|
+
NestJS module for seamless integration with the WhatsApp Cloud API, supporting sandbox & live modes, multi-clients, webhooks, microservice transport, metrics, and health checks.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Send 10 message types: text, image, audio, document, location, template, video, sticker, reaction, and interactive — all returning the message ID (`Promise<string>`) with optional reply threading via `replyToMessageId`
|
|
13
|
+
- Session management helpers (`startSession`, `endSession`)
|
|
14
|
+
- Sandbox mode for rapid testing
|
|
15
|
+
- Live mode for production with template enforcement and rate limits
|
|
16
|
+
- Webhook verification & event emitting
|
|
17
|
+
- Nest microservice transport (TCP)
|
|
18
|
+
- Prometheus metrics and Nest Terminus health indicator
|
|
19
|
+
- Full TypeScript support (CJS & ESM)
|
|
20
|
+
- Easy configuration via `forRoot` / `forRootAsync`
|
|
21
|
+
- CLI schematic: `nest generate whatsapp`
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install nest-whatsapp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Step 1:** Create the config file `src/config/whatsapp.config.ts`:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { registerAs } from '@nestjs/config';
|
|
33
|
+
import * as Joi from 'joi';
|
|
34
|
+
|
|
35
|
+
export default registerAs('whatsapp', () => ({
|
|
36
|
+
mode: process.env.WHATSAPP_MODE,
|
|
37
|
+
sandbox: {
|
|
38
|
+
testPhoneNumberId: process.env.WHATSAPP_SANDBOX_PHONE_NUMBER_ID,
|
|
39
|
+
temporaryAccessToken: process.env.WHATSAPP_SANDBOX_ACCESS_TOKEN,
|
|
40
|
+
testRecipients: process.env.WHATSAPP_SANDBOX_TEST_RECIPIENTS?.split(',') || [],
|
|
41
|
+
},
|
|
42
|
+
live: {
|
|
43
|
+
businessAccountId: process.env.WHATSAPP_LIVE_BUSINESS_ACCOUNT_ID,
|
|
44
|
+
phoneNumberId: process.env.WHATSAPP_LIVE_PHONE_NUMBER_ID,
|
|
45
|
+
accessToken: process.env.WHATSAPP_LIVE_ACCESS_TOKEN,
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
export const WhatsappConfigSchema = Joi.object({
|
|
50
|
+
WHATSAPP_MODE: Joi.string().valid('sandbox', 'live').required(),
|
|
51
|
+
WHATSAPP_SANDBOX_PHONE_NUMBER_ID: Joi.string().when('WHATSAPP_MODE', {
|
|
52
|
+
is: 'sandbox',
|
|
53
|
+
then: Joi.required(),
|
|
54
|
+
}),
|
|
55
|
+
WHATSAPP_SANDBOX_ACCESS_TOKEN: Joi.string().when('WHATSAPP_MODE', {
|
|
56
|
+
is: 'sandbox',
|
|
57
|
+
then: Joi.required(),
|
|
58
|
+
}),
|
|
59
|
+
WHATSAPP_SANDBOX_TEST_RECIPIENTS: Joi.string().when('WHATSAPP_MODE', {
|
|
60
|
+
is: 'sandbox',
|
|
61
|
+
then: Joi.required(),
|
|
62
|
+
}),
|
|
63
|
+
WHATSAPP_LIVE_BUSINESS_ACCOUNT_ID: Joi.string().when('WHATSAPP_MODE', {
|
|
64
|
+
is: 'live',
|
|
65
|
+
then: Joi.required(),
|
|
66
|
+
}),
|
|
67
|
+
WHATSAPP_LIVE_PHONE_NUMBER_ID: Joi.string().when('WHATSAPP_MODE', {
|
|
68
|
+
is: 'live',
|
|
69
|
+
then: Joi.required(),
|
|
70
|
+
}),
|
|
71
|
+
WHATSAPP_LIVE_ACCESS_TOKEN: Joi.string().when('WHATSAPP_MODE', {
|
|
72
|
+
is: 'live',
|
|
73
|
+
then: Joi.required(),
|
|
74
|
+
}),
|
|
75
|
+
WHATSAPP_WEBHOOK_VERIFY_TOKEN: Joi.string().required(),
|
|
76
|
+
WHATSAPP_APP_SECRET: Joi.string().required(),
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Step 2:** Set up your module `src/app.module.ts`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Module } from '@nestjs/common';
|
|
84
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
85
|
+
import whatsappConfig, { WhatsappConfigSchema } from './config/whatsapp.config';
|
|
86
|
+
import { WhatsAppModule } from 'nest-whatsapp';
|
|
87
|
+
|
|
88
|
+
@Module({
|
|
89
|
+
imports: [
|
|
90
|
+
ConfigModule.forRoot({
|
|
91
|
+
isGlobal: true,
|
|
92
|
+
load: [whatsappConfig],
|
|
93
|
+
validationSchema: WhatsappConfigSchema,
|
|
94
|
+
}),
|
|
95
|
+
WhatsAppModule.forRootAsync({
|
|
96
|
+
imports: [ConfigModule],
|
|
97
|
+
inject: [ConfigService],
|
|
98
|
+
useFactory: (cs: ConfigService) => {
|
|
99
|
+
const cfg = cs.get('whatsapp');
|
|
100
|
+
return cfg.mode === 'sandbox'
|
|
101
|
+
? {
|
|
102
|
+
mode: 'sandbox',
|
|
103
|
+
testPhoneNumberId: cfg.sandbox.testPhoneNumberId,
|
|
104
|
+
temporaryAccessToken: cfg.sandbox.temporaryAccessToken,
|
|
105
|
+
testRecipients: cfg.sandbox.testRecipients,
|
|
106
|
+
}
|
|
107
|
+
: {
|
|
108
|
+
mode: 'live',
|
|
109
|
+
businessAccountId: cfg.live.businessAccountId,
|
|
110
|
+
phoneNumberId: cfg.live.phoneNumberId,
|
|
111
|
+
accessToken: cfg.live.accessToken,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
],
|
|
116
|
+
})
|
|
117
|
+
export class AppModule {}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Configuration
|
|
121
|
+
|
|
122
|
+
Use environment variables or secret manager via `forRootAsync`:
|
|
123
|
+
|
|
124
|
+
| Variable | Description | Required |
|
|
125
|
+
| ----------------------------------- | ----------------------------------------- | -------------------- |
|
|
126
|
+
| `WHATSAPP_MODE` | `sandbox` or `live` | yes |
|
|
127
|
+
| `WHATSAPP_SANDBOX_PHONE_NUMBER_ID` | Sandbox phone number ID | if `sandbox` |
|
|
128
|
+
| `WHATSAPP_SANDBOX_ACCESS_TOKEN` | Sandbox temporary access token | if `sandbox` |
|
|
129
|
+
| `WHATSAPP_SANDBOX_TEST_RECIPIENTS` | Comma-separated test recipient numbers | if `sandbox` |
|
|
130
|
+
| `WHATSAPP_LIVE_BUSINESS_ACCOUNT_ID` | Live business account ID | if `live` |
|
|
131
|
+
| `WHATSAPP_LIVE_PHONE_NUMBER_ID` | Live phone number ID | if `live` |
|
|
132
|
+
| `WHATSAPP_LIVE_ACCESS_TOKEN` | Live long-lived access token | if `live` |
|
|
133
|
+
| `WHATSAPP_WEBHOOK_VERIFY_TOKEN` | Webhook verification token | yes |
|
|
134
|
+
| `WHATSAPP_APP_SECRET` | App secret for HMAC verification | yes |
|
|
135
|
+
| `WHATSAPP_WEBHOOK_MAX_BODY_BYTES` | Maximum raw webhook payload size | no (default 2 MB) |
|
|
136
|
+
| `WHATSAPP_MASK_PHONE_LOGS` | Mask phone numbers in logs (`true/false`) | no (default `true`) |
|
|
137
|
+
| `WHATSAPP_LOG_MESSAGE_BODIES` | Log outbound payload bodies (dangerous) | no (default `false`) |
|
|
138
|
+
| `WHATSAPP_HEALTH_TIMEOUT_MS` | Graph API health probe timeout (ms) | no (default `3000`) |
|
|
139
|
+
| `WHATSAPP_HEALTH_SKIP_EXTERNAL` | Skip outbound health probe (`true/false`) | no (default `false`) |
|
|
140
|
+
|
|
141
|
+
### Advanced HTTP settings (optional)
|
|
142
|
+
|
|
143
|
+
- `WHATSAPP_GRAPH_API_VERSION` — Graph API version used for outbound requests. Default: `v17.0`.
|
|
144
|
+
- `WHATSAPP_HTTP_TIMEOUT_MS` — Axios request timeout in milliseconds. Default: `10000`.
|
|
145
|
+
- `WHATSAPP_HTTP_RETRIES` — Number of retry attempts for retryable errors (network/5xx/429). Default: `2`.
|
|
146
|
+
- `WHATSAPP_HTTP_MAX_RETRY_DELAY_MS` — Cap for exponential backoff with jitter. Default: `5000`.
|
|
147
|
+
- Per-client overrides: set `httpConfig` on each `WhatsAppClientOptions` entry to merge in custom Axios settings (proxies, params, etc.). Authorization headers are managed automatically.
|
|
148
|
+
|
|
149
|
+
### Runtime tuning
|
|
150
|
+
|
|
151
|
+
To override the global HTTP/retry/logging defaults via DI instead of environment variables, provide `WHATSAPP_RUNTIME_OPTIONS`:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { Module } from '@nestjs/common';
|
|
155
|
+
import { WhatsAppModule, WHATSAPP_RUNTIME_OPTIONS } from 'nest-whatsapp';
|
|
156
|
+
|
|
157
|
+
@Module({
|
|
158
|
+
imports: [WhatsAppModule.forRoot(/* ... */)],
|
|
159
|
+
providers: [
|
|
160
|
+
{
|
|
161
|
+
provide: WHATSAPP_RUNTIME_OPTIONS,
|
|
162
|
+
useValue: { httpTimeoutMs: 5000, maskPhoneLogs: false },
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
})
|
|
166
|
+
export class MessagingModule {}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
When this provider is absent, the module falls back to the environment variables listed above.
|
|
170
|
+
|
|
171
|
+
## Usage Examples
|
|
172
|
+
|
|
173
|
+
### Handling Incoming Messages
|
|
174
|
+
|
|
175
|
+
The webhook endpoint (`GET/POST /whatsapp/webhook`) is **automatically registered** when you import `WhatsAppModule`. You do not need to write a controller for it. To react to incoming messages, inject `WhatsAppEvents` into your own service and subscribe in `onModuleInit`:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { Injectable, OnModuleInit } from ‘@nestjs/common’;
|
|
179
|
+
import { WhatsAppEvents } from ‘nest-whatsapp’;
|
|
180
|
+
|
|
181
|
+
@Injectable()
|
|
182
|
+
export class MessageHandlerService implements OnModuleInit {
|
|
183
|
+
constructor(private readonly events: WhatsAppEvents) {}
|
|
184
|
+
|
|
185
|
+
onModuleInit(): void {
|
|
186
|
+
this.events.onTextReceived(({ message, contact }) => {
|
|
187
|
+
console.log(‘Text:’, message.text.body, ‘from’, contact?.wa_id);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
> Tip: install `eventemitter2` or `@nestjs/event-emitter` if you want wildcard listeners. Without them the module falls back to Node’s `events` emitter, which supports the same API used here but without the extra helpers.
|
|
194
|
+
|
|
195
|
+
### Microservice Transport
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
@Module({
|
|
199
|
+
imports: [WhatsAppModule.forMicroservice({ host: 'localhost', port: 4000 })],
|
|
200
|
+
})
|
|
201
|
+
export class MicroAppModule {}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Metrics & Health
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
@Controller('metrics')
|
|
208
|
+
export class MetricsController {
|
|
209
|
+
constructor(private readonly metrics: WhatsAppMetricsService) {}
|
|
210
|
+
@Get() public metrics() {
|
|
211
|
+
return this.metrics.getMetrics();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Exposed Prometheus metrics:
|
|
217
|
+
|
|
218
|
+
- `whatsapp_messages_sent_total` — counter, increments on successful message sends. Labels: `type`, `mode`.
|
|
219
|
+
- `whatsapp_errors_total` — counter, increments on send errors. Labels: `type`, `mode`, `status`.
|
|
220
|
+
- `whatsapp_webhook_events_total` — counter, increments on webhook receive.
|
|
221
|
+
- `whatsapp_request_duration_seconds` — histogram, outbound request latency. Labels: `type`, `mode`, `status`.
|
|
222
|
+
- `whatsapp_build_info` — gauge with labels `version`, `node_version`, `environment`, always `1` for scrape-friendly metadata.
|
|
223
|
+
|
|
224
|
+
Tip: use relabeling to add instance labels; see the example app for the `/metrics` endpoint.
|
|
225
|
+
|
|
226
|
+
### Webhook Security & CSRF
|
|
227
|
+
|
|
228
|
+
- Signature verification: the controller validates `x-hub-signature-256` with an HMAC‐SHA256 using your `WHATSAPP_APP_SECRET`, using constant‑time comparison.
|
|
229
|
+
- Raw body is required and size-limited: set `WHATSAPP_WEBHOOK_MAX_BODY_BYTES` (default `2_000_000`) and ensure your Nest bootstrap captures the raw buffer with the same `bodyParser.json` limit:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
app.use(
|
|
233
|
+
bodyParser.json({
|
|
234
|
+
limit: '2mb',
|
|
235
|
+
verify: (req, _res, buf) => ((req as any).rawBody = buf),
|
|
236
|
+
})
|
|
237
|
+
);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
- CSRF: not required for the WhatsApp webhook route because requests are authenticated by HMAC and originate from Meta. For your own browser‑facing endpoints, configure CSRF as appropriate for your app.
|
|
241
|
+
|
|
242
|
+
### Sandbox Safety
|
|
243
|
+
|
|
244
|
+
- Sandbox sends are restricted to the `testRecipients` allow‑list supplied in `WhatsAppSandboxOptions`. Calls to `send*` will fail fast if the list is empty or the recipient is not whitelisted.
|
|
245
|
+
- Logs mask phone numbers by default; opt out via `WHATSAPP_MASK_PHONE_LOGS=false`.
|
|
246
|
+
- Payload bodies are **not** logged unless you explicitly enable `WHATSAPP_LOG_MESSAGE_BODIES=true`.
|
|
247
|
+
|
|
248
|
+
## Typed Events & Helpers
|
|
249
|
+
|
|
250
|
+
- Facade `WhatsAppEvents` exposes typed events:
|
|
251
|
+
- Raw: `message_received`
|
|
252
|
+
- Sub-events: `text_received`, `image_received`, `audio_received`, `document_received`, `location_received`, `template_received`, `interactive_received`, `contacts_received`, `system_received`, `order_received`, `product_received`, `reaction_received`.
|
|
253
|
+
- Delivery receipts: `status_received` — carries `WhatsAppStatusEvent` with delivery and read receipt data; subscribe via `onStatusReceived()` / `offStatusReceived()`.
|
|
254
|
+
- Subscribe (inside `onModuleInit` or a constructor-safe lifecycle hook):
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import { Injectable, OnModuleInit } from '@nestjs/common';
|
|
258
|
+
import { WhatsAppEvents } from 'nest-whatsapp';
|
|
259
|
+
|
|
260
|
+
@Injectable()
|
|
261
|
+
export class MessageHandlerService implements OnModuleInit {
|
|
262
|
+
constructor(private readonly events: WhatsAppEvents) {}
|
|
263
|
+
|
|
264
|
+
onModuleInit(): void {
|
|
265
|
+
this.events.onTextReceived(({ message, contact }) => {
|
|
266
|
+
console.log('Text:', message.text.body, 'from', contact?.wa_id);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- Helpers in `utils/webhook`:
|
|
273
|
+
- `getFirstMessage`, `getFirstContact`, `getAllMessages`, `getAllStatuses`
|
|
274
|
+
- Type guards: `isTextMessage`, `isImageMessage`, `isInteractiveMessage`, etc.
|
|
275
|
+
|
|
276
|
+
## Health & Microservice (optional)
|
|
277
|
+
|
|
278
|
+
### Health Indicator
|
|
279
|
+
|
|
280
|
+
- Install peer: `npm i -S @nestjs/terminus`
|
|
281
|
+
- Import health providers only when needed:
|
|
282
|
+
- `WHATSAPP_HEALTH_TIMEOUT_MS` controls the outbound probe timeout; use `WHATSAPP_HEALTH_SKIP_EXTERNAL=true` for environments without egress.
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import { Module } from '@nestjs/common';
|
|
286
|
+
import { WhatsAppModule } from 'nest-whatsapp';
|
|
287
|
+
|
|
288
|
+
@Module({
|
|
289
|
+
imports: [WhatsAppModule.forHealth()],
|
|
290
|
+
})
|
|
291
|
+
export class HealthModule {}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Microservice Client
|
|
295
|
+
|
|
296
|
+
- Install peer if using microservices: `npm i -S @nestjs/microservices`
|
|
297
|
+
- Register a TCP client with lazy-loaded microservices support:
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
import { Module } from '@nestjs/common';
|
|
301
|
+
import { WhatsAppModule } from 'nest-whatsapp';
|
|
302
|
+
|
|
303
|
+
@Module({
|
|
304
|
+
imports: [
|
|
305
|
+
WhatsAppModule.forMicroservice({ host: '127.0.0.1', port: 4000, clientName: 'WA_CLIENT' }),
|
|
306
|
+
],
|
|
307
|
+
})
|
|
308
|
+
export class MessagingModule {}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
- `clientName` must be non-empty when provided; defaults to `WHATSAPP_MICROSERVICE`.
|
|
312
|
+
- Use DTOs + `class-validator` to validate inbound TCP payloads (see `examples/microservice` for ready-made `wa.sendText`, `wa.sendTemplate`, `wa.sendMedia`, `wa.sendDocument`, and `wa.sendLocation` patterns).
|
|
313
|
+
|
|
314
|
+
## CLI Schematic
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
nest generate whatsapp
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Schematic Usage (standalone)
|
|
321
|
+
|
|
322
|
+
- Build first: `npm run build`
|
|
323
|
+
- Sandbox with health + micro:
|
|
324
|
+
- `npx schematics nest-whatsapp:whatsapp --module=src/app.module.ts --mode=sandbox --add-health --add-micro --host=127.0.0.1 --port=4000`
|
|
325
|
+
- Sandbox with explicit creds:
|
|
326
|
+
- `npx schematics nest-whatsapp:whatsapp --module=src/app.module.ts --mode=sandbox --test-phone-number-id=123 --temporary-access-token=TOKEN --test-recipients=+15551234567,+15557654321`
|
|
327
|
+
- Live configuration:
|
|
328
|
+
- `npx schematics nest-whatsapp:whatsapp --module=src/app.module.ts --mode=live --business-account-id=BA_ID --phone-number-id=PN_ID --access-token=ACCESS_TOKEN`
|
|
329
|
+
|
|
330
|
+
#### Notes
|
|
331
|
+
|
|
332
|
+
- Options use dashed names (e.g., `--add-health`, not `--addHealth`).
|
|
333
|
+
- The schematic now wires `WhatsAppModule.forRootAsync(...)` + `ConfigModule` by default; adjust the generated factory to map your configuration layer if needed.
|
|
334
|
+
|
|
335
|
+
## Documentation
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
npx typedoc --out docs src
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Migration Notes
|
|
342
|
+
|
|
343
|
+
- Webhook payloads are now capped by `WHATSAPP_WEBHOOK_MAX_BODY_BYTES` (default 2 MB). Increase the limit explicitly if you previously accepted larger requests.
|
|
344
|
+
- Sandbox sends strictly enforce `testRecipients`; provide at least one recipient or use live mode.
|
|
345
|
+
- Phone numbers are masked in logs by default and payload bodies remain hidden unless `WHATSAPP_LOG_MESSAGE_BODIES=true`.
|
|
346
|
+
- The schematic and examples now default to `WhatsAppModule.forRootAsync` with `@nestjs/config`. Update custom templates accordingly.
|
|
347
|
+
|
|
348
|
+
## Run Examples
|
|
349
|
+
|
|
350
|
+
- Install example deps: `npm run examples:install`
|
|
351
|
+
- Option A (recommended): use the published package (no extra steps).
|
|
352
|
+
- Option B (local development): build and install locally
|
|
353
|
+
- `npm run build && npm pack` (note the generated `.tgz` file)
|
|
354
|
+
- In each example folder: `npm install ../../nest-whatsapp-*.tgz`
|
|
355
|
+
|
|
356
|
+
### Basic HTTP example
|
|
357
|
+
|
|
358
|
+
- Env (sandbox mode):
|
|
359
|
+
- `WHATSAPP_MODE=sandbox`
|
|
360
|
+
- `WHATSAPP_SANDBOX_PHONE_NUMBER_ID=...`
|
|
361
|
+
- `WHATSAPP_SANDBOX_ACCESS_TOKEN=...`
|
|
362
|
+
- `WHATSAPP_SANDBOX_TEST_RECIPIENTS=+15551234567`
|
|
363
|
+
- Env (live mode):
|
|
364
|
+
- `WHATSAPP_MODE=live`
|
|
365
|
+
- `WHATSAPP_LIVE_BUSINESS_ACCOUNT_ID=...`
|
|
366
|
+
- `WHATSAPP_LIVE_PHONE_NUMBER_ID=...`
|
|
367
|
+
- `WHATSAPP_LIVE_ACCESS_TOKEN=...`
|
|
368
|
+
- Run: `npm run example:basic`
|
|
369
|
+
- Send a message:
|
|
370
|
+
- `curl -X POST localhost:3000/messages/text -H 'Content-Type: application/json' -d '{"to":"+15551234567","message":"Hello"}'`
|
|
371
|
+
|
|
372
|
+
### Microservice example
|
|
373
|
+
|
|
374
|
+
- Env:
|
|
375
|
+
- `WHATSAPP_MICROSERVICE_HOST=127.0.0.1`
|
|
376
|
+
- `WHATSAPP_MICROSERVICE_PORT=4000`
|
|
377
|
+
- Run: `npm run example:micro`
|
|
378
|
+
- Run demo client: `npm --prefix examples/microservice run demo`
|
|
379
|
+
|
|
380
|
+
## License
|
|
381
|
+
|
|
382
|
+
Apache-2.0
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.WhatsAppController = void 0;
|
|
49
|
+
const common_1 = require("@nestjs/common");
|
|
50
|
+
const whatsapp_events_1 = require("../services/whatsapp.events");
|
|
51
|
+
const config_1 = require("@nestjs/config");
|
|
52
|
+
const crypto = __importStar(require("crypto"));
|
|
53
|
+
const whatsapp_metrics_1 = require("../services/whatsapp.metrics");
|
|
54
|
+
let WhatsAppController = class WhatsAppController {
|
|
55
|
+
events;
|
|
56
|
+
configService;
|
|
57
|
+
metrics;
|
|
58
|
+
constructor(events, configService, metrics) {
|
|
59
|
+
this.events = events;
|
|
60
|
+
this.configService = configService;
|
|
61
|
+
this.metrics = metrics;
|
|
62
|
+
}
|
|
63
|
+
verify(req) {
|
|
64
|
+
const mode = req.query['hub.mode'];
|
|
65
|
+
const token = req.query['hub.verify_token'];
|
|
66
|
+
const rawChallenge = req.query['hub.challenge'];
|
|
67
|
+
if (mode === 'subscribe' &&
|
|
68
|
+
token ===
|
|
69
|
+
(this.configService?.get('WHATSAPP_WEBHOOK_VERIFY_TOKEN') ??
|
|
70
|
+
process.env['WHATSAPP_WEBHOOK_VERIFY_TOKEN'])) {
|
|
71
|
+
const challenge = typeof rawChallenge === 'string' ? rawChallenge : '';
|
|
72
|
+
const MAX_CHALLENGE_LENGTH = 256;
|
|
73
|
+
if (challenge.length === 0 ||
|
|
74
|
+
challenge.length > MAX_CHALLENGE_LENGTH ||
|
|
75
|
+
!/^[A-Za-z0-9._-]+$/.test(challenge)) {
|
|
76
|
+
throw new common_1.UnauthorizedException();
|
|
77
|
+
}
|
|
78
|
+
return challenge;
|
|
79
|
+
}
|
|
80
|
+
throw new common_1.UnauthorizedException();
|
|
81
|
+
}
|
|
82
|
+
receive(req, signature) {
|
|
83
|
+
const rawBody = req.rawBody;
|
|
84
|
+
const appSecret = this.configService?.get('WHATSAPP_APP_SECRET') ?? process.env['WHATSAPP_APP_SECRET'];
|
|
85
|
+
const maxBodyBytes = this.resolveMaxBodyBytes();
|
|
86
|
+
if (!appSecret || !rawBody || !signature) {
|
|
87
|
+
throw new common_1.UnauthorizedException();
|
|
88
|
+
}
|
|
89
|
+
if (rawBody.length > maxBodyBytes) {
|
|
90
|
+
throw new common_1.PayloadTooLargeException(`Webhook payload exceeds ${maxBodyBytes} bytes, request rejected`);
|
|
91
|
+
}
|
|
92
|
+
// Enforce prefix and perform a timing-safe comparison of the HMAC
|
|
93
|
+
const prefix = 'sha256=';
|
|
94
|
+
if (!signature.startsWith(prefix)) {
|
|
95
|
+
throw new common_1.UnauthorizedException();
|
|
96
|
+
}
|
|
97
|
+
const providedHex = signature.slice(prefix.length);
|
|
98
|
+
const expectedHex = crypto.createHmac('sha256', appSecret).update(rawBody).digest('hex');
|
|
99
|
+
const provided = Buffer.from(providedHex, 'hex');
|
|
100
|
+
const expected = Buffer.from(expectedHex, 'hex');
|
|
101
|
+
if (provided.length !== expected.length || !crypto.timingSafeEqual(provided, expected)) {
|
|
102
|
+
throw new common_1.UnauthorizedException();
|
|
103
|
+
}
|
|
104
|
+
this.events.emitMessageReceived(req.body);
|
|
105
|
+
this.metrics?.incrementWebhookEvents();
|
|
106
|
+
return 'EVENT_RECEIVED';
|
|
107
|
+
}
|
|
108
|
+
resolveMaxBodyBytes() {
|
|
109
|
+
const fromConfig = this.configService?.get('WHATSAPP_WEBHOOK_MAX_BODY_BYTES') ??
|
|
110
|
+
process.env['WHATSAPP_WEBHOOK_MAX_BODY_BYTES'];
|
|
111
|
+
const parsed = Number(fromConfig ?? 2_000_000);
|
|
112
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 2_000_000;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.WhatsAppController = WhatsAppController;
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, common_1.Get)(),
|
|
118
|
+
__param(0, (0, common_1.Req)()),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", [Object]),
|
|
121
|
+
__metadata("design:returntype", String)
|
|
122
|
+
], WhatsAppController.prototype, "verify", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
(0, common_1.Post)(),
|
|
125
|
+
__param(0, (0, common_1.Req)()),
|
|
126
|
+
__param(1, (0, common_1.Headers)('x-hub-signature-256')),
|
|
127
|
+
__metadata("design:type", Function),
|
|
128
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
129
|
+
__metadata("design:returntype", String)
|
|
130
|
+
], WhatsAppController.prototype, "receive", null);
|
|
131
|
+
exports.WhatsAppController = WhatsAppController = __decorate([
|
|
132
|
+
(0, common_1.Controller)('whatsapp/webhook'),
|
|
133
|
+
__param(1, (0, common_1.Optional)()),
|
|
134
|
+
__param(2, (0, common_1.Optional)()),
|
|
135
|
+
__metadata("design:paramtypes", [whatsapp_events_1.WhatsAppEvents,
|
|
136
|
+
config_1.ConfigService,
|
|
137
|
+
whatsapp_metrics_1.WhatsAppMetricsService])
|
|
138
|
+
], WhatsAppController);
|
|
139
|
+
//# sourceMappingURL=whatsapp.controller.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhatsAppSandboxRecipientException = exports.WhatsAppRateLimitException = exports.WhatsAppAuthException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class WhatsAppAuthException extends common_1.HttpException {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('WhatsApp authentication failed', common_1.HttpStatus.UNAUTHORIZED);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.WhatsAppAuthException = WhatsAppAuthException;
|
|
11
|
+
class WhatsAppRateLimitException extends common_1.HttpException {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('WhatsApp rate limit exceeded', common_1.HttpStatus.TOO_MANY_REQUESTS);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.WhatsAppRateLimitException = WhatsAppRateLimitException;
|
|
17
|
+
class WhatsAppSandboxRecipientException extends common_1.HttpException {
|
|
18
|
+
constructor(message = 'Recipient not allowed in WhatsApp sandbox mode') {
|
|
19
|
+
super(message, common_1.HttpStatus.BAD_REQUEST);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.WhatsAppSandboxRecipientException = WhatsAppSandboxRecipientException;
|
|
23
|
+
//# sourceMappingURL=whatsapp.exceptions.js.map
|