Skip to content

Commit

Permalink
adjusting route for proper webhook definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Dec 23, 2023
1 parent 986d901 commit d384f2f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ networks:
services:
api:
container_name: codechat_api
image: codechat/develop
image: codechat/api:latest
restart: unless-stopped
ports:
- 8084:8084
Expand Down
3 changes: 2 additions & 1 deletion src/guards/instance.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class InstanceGuard {
req.originalUrl.includes('/instance/create') ||
req.originalUrl.includes('/instance/fetchInstances') ||
req.originalUrl.includes('/instance/qrcode') ||
req.originalUrl.includes('/instance/connect')
req.originalUrl.includes('/instance/connect') ||
req.originalUrl.includes('/webhook')
) {
return next();
}
Expand Down
5 changes: 5 additions & 0 deletions src/repository/repository.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class Repository extends PrismaClient {
continue;
}

if (!find?.events) {
break;
}

const k = `ARRAY['${key}']`;
const v = `to_jsonb(${value}::boolean)`;

Expand All @@ -106,6 +110,7 @@ export class Repository extends PrismaClient {
data: {
url: data?.url,
enabled: data?.enabled,
events: !find?.events ? data?.events : undefined,
},
select: {
id: true,
Expand Down
1 change: 1 addition & 0 deletions src/whatsapp/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class InstanceController {

switch (state) {
case 'close':
await instance.loadWebhook();
await instance.connectToWhatsapp();
await delay(2000);
return instance.qrCode;
Expand Down
9 changes: 2 additions & 7 deletions src/whatsapp/controllers/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* └──────────────────────────────────────────────────────────────────────────────┘
*/

import { isURL } from 'class-validator';
import { BadRequestException } from '../../exceptions';
import { InstanceDto } from '../dto/instance.dto';
import { WebhookDto } from '../dto/webhook.dto';
import { WebhookService } from '../services/webhook.service';
Expand All @@ -44,13 +42,10 @@ export class WebhookController {
constructor(private readonly webhookService: WebhookService) {}

public async createWebhook(instance: InstanceDto, data: WebhookDto) {
if (!isURL(data.url)) {
throw new BadRequestException('Invalid "url" property');
}
return this.webhookService.create(instance, data);
return await this.webhookService.create(instance, data);
}

public async findWebhook(instance: InstanceDto) {
return this.webhookService.find(instance);
return await this.webhookService.find(instance);
}
}

0 comments on commit d384f2f

Please sign in to comment.