Skip to content

Commit

Permalink
fix: Create instance with settings
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Jul 25, 2023
1 parent 62e2a8a commit c314d00
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/whatsapp/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Logger } from '../../config/logger.config';
import { wa } from '../types/wa.types';
import { RedisCache } from '../../db/redis.client';
import { isURL } from 'class-validator';
import { SettingsService } from '../services/settings.service';

export class InstanceController {
constructor(
Expand All @@ -23,6 +24,7 @@ export class InstanceController {
private readonly authService: AuthService,
private readonly webhookService: WebhookService,
private readonly chatwootService: ChatwootService,
private readonly settingsService: SettingsService,
private readonly cache: RedisCache,
) {}

Expand All @@ -40,6 +42,12 @@ export class InstanceController {
chatwoot_token,
chatwoot_url,
chatwoot_sign_msg,
reject_call,
msg_call,
groups_ignore,
always_online,
read_messages,
read_status,
}: InstanceDto) {
try {
this.logger.verbose('requested createInstance from ' + instanceName + ' instance');
Expand Down Expand Up @@ -102,6 +110,20 @@ export class InstanceController {
}
}

this.logger.verbose('creating settings');
const settings: wa.LocalSettings = {
reject_call: reject_call || false,
msg_call: msg_call || '',
groups_ignore: groups_ignore || false,
always_online: always_online || false,
read_messages: read_messages || false,
read_status: read_status || false,
};

this.logger.verbose('settings: ' + JSON.stringify(settings));

this.settingsService.create(instance, settings);

if (!chatwoot_account_id || !chatwoot_token || !chatwoot_url) {
let getQrcode: wa.QrCode;

Expand All @@ -121,6 +143,7 @@ export class InstanceController {
webhook,
webhook_by_events,
events: getEvents,
settings,
qrcode: getQrcode,
};

Expand Down Expand Up @@ -179,6 +202,7 @@ export class InstanceController {
webhook,
webhook_by_events,
events: getEvents,
settings,
chatwoot: {
enabled: true,
account_id: chatwoot_account_id,
Expand Down
12 changes: 9 additions & 3 deletions src/whatsapp/dto/instance.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
export class InstanceDto {
instanceName: string;
webhook?: string;
webhook_by_events?: boolean;
events?: string[];
qrcode?: boolean;
number?: string;
token?: string;
webhook?: string;
webhook_by_events?: boolean;
events?: string[];
reject_call?: boolean;
msg_call?: string;
groups_ignore?: boolean;
always_online?: boolean;
read_messages?: boolean;
read_status?: boolean;
chatwoot_account_id?: string;
chatwoot_token?: string;
chatwoot_url?: string;
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/whatsapp.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const instanceController = new InstanceController(
authService,
webhookService,
chatwootService,
settingsService,
cache,
);
export const viewsController = new ViewsController(waMonitor, configService);
Expand Down

0 comments on commit c314d00

Please sign in to comment.