Skip to content

Commit c314d00

Browse files
committed
fix: Create instance with settings
1 parent 62e2a8a commit c314d00

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/whatsapp/controllers/instance.controller.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Logger } from '../../config/logger.config';
1313
import { wa } from '../types/wa.types';
1414
import { RedisCache } from '../../db/redis.client';
1515
import { isURL } from 'class-validator';
16+
import { SettingsService } from '../services/settings.service';
1617

1718
export class InstanceController {
1819
constructor(
@@ -23,6 +24,7 @@ export class InstanceController {
2324
private readonly authService: AuthService,
2425
private readonly webhookService: WebhookService,
2526
private readonly chatwootService: ChatwootService,
27+
private readonly settingsService: SettingsService,
2628
private readonly cache: RedisCache,
2729
) {}
2830

@@ -40,6 +42,12 @@ export class InstanceController {
4042
chatwoot_token,
4143
chatwoot_url,
4244
chatwoot_sign_msg,
45+
reject_call,
46+
msg_call,
47+
groups_ignore,
48+
always_online,
49+
read_messages,
50+
read_status,
4351
}: InstanceDto) {
4452
try {
4553
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
@@ -102,6 +110,20 @@ export class InstanceController {
102110
}
103111
}
104112

113+
this.logger.verbose('creating settings');
114+
const settings: wa.LocalSettings = {
115+
reject_call: reject_call || false,
116+
msg_call: msg_call || '',
117+
groups_ignore: groups_ignore || false,
118+
always_online: always_online || false,
119+
read_messages: read_messages || false,
120+
read_status: read_status || false,
121+
};
122+
123+
this.logger.verbose('settings: ' + JSON.stringify(settings));
124+
125+
this.settingsService.create(instance, settings);
126+
105127
if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
106128
let getQrcode: wa.QrCode;
107129

@@ -121,6 +143,7 @@ export class InstanceController {
121143
webhook,
122144
webhook_by_events,
123145
events: getEvents,
146+
settings,
124147
qrcode: getQrcode,
125148
};
126149

@@ -179,6 +202,7 @@ export class InstanceController {
179202
webhook,
180203
webhook_by_events,
181204
events: getEvents,
205+
settings,
182206
chatwoot: {
183207
enabled: true,
184208
account_id: chatwoot_account_id,

src/whatsapp/dto/instance.dto.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
export class InstanceDto {
22
instanceName: string;
3-
webhook?: string;
4-
webhook_by_events?: boolean;
5-
events?: string[];
63
qrcode?: boolean;
74
number?: string;
85
token?: string;
6+
webhook?: string;
7+
webhook_by_events?: boolean;
8+
events?: string[];
9+
reject_call?: boolean;
10+
msg_call?: string;
11+
groups_ignore?: boolean;
12+
always_online?: boolean;
13+
read_messages?: boolean;
14+
read_status?: boolean;
915
chatwoot_account_id?: string;
1016
chatwoot_token?: string;
1117
chatwoot_url?: string;

src/whatsapp/whatsapp.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const instanceController = new InstanceController(
9494
authService,
9595
webhookService,
9696
chatwootService,
97+
settingsService,
9798
cache,
9899
);
99100
export const viewsController = new ViewsController(waMonitor, configService);

0 commit comments

Comments
 (0)