Skip to content

Commit 29e2cfa

Browse files
committed
feat: pusher event integration
1 parent f38f3e5 commit 29e2cfa

File tree

19 files changed

+540
-29
lines changed

19 files changed

+540
-29
lines changed

.env.example

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,41 @@ SQS_REGION=
8888
WEBSOCKET_ENABLED=false
8989
WEBSOCKET_GLOBAL_EVENTS=false
9090

91+
# Pusher - Environment variables
92+
PUSHER_ENABLED=false
93+
PUSHER_GLOBAL_ENABLED=false
94+
PUSHER_GLOBAL_APP_ID=
95+
PUSHER_GLOBAL_KEY=
96+
PUSHER_GLOBAL_SECRET=
97+
PUSHER_GLOBAL_CLUSTER=
98+
PUSHER_GLOBAL_USE_TLS=true
99+
# Choose the events you want to send to Pusher
100+
PUSHER_EVENTS_APPLICATION_STARTUP=true
101+
PUSHER_EVENTS_QRCODE_UPDATED=true
102+
PUSHER_EVENTS_MESSAGES_SET=true
103+
PUSHER_EVENTS_MESSAGES_UPSERT=true
104+
PUSHER_EVENTS_MESSAGES_EDITED=true
105+
PUSHER_EVENTS_MESSAGES_UPDATE=true
106+
PUSHER_EVENTS_MESSAGES_DELETE=true
107+
PUSHER_EVENTS_SEND_MESSAGE=true
108+
PUSHER_EVENTS_CONTACTS_SET=true
109+
PUSHER_EVENTS_CONTACTS_UPSERT=true
110+
PUSHER_EVENTS_CONTACTS_UPDATE=true
111+
PUSHER_EVENTS_PRESENCE_UPDATE=true
112+
PUSHER_EVENTS_CHATS_SET=true
113+
PUSHER_EVENTS_CHATS_UPSERT=true
114+
PUSHER_EVENTS_CHATS_UPDATE=true
115+
PUSHER_EVENTS_CHATS_DELETE=true
116+
PUSHER_EVENTS_GROUPS_UPSERT=true
117+
PUSHER_EVENTS_GROUPS_UPDATE=true
118+
PUSHER_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
119+
PUSHER_EVENTS_CONNECTION_UPDATE=true
120+
PUSHER_EVENTS_LABELS_EDIT=true
121+
PUSHER_EVENTS_LABELS_ASSOCIATION=true
122+
PUSHER_EVENTS_CALL=true
123+
PUSHER_EVENTS_TYPEBOT_START=false
124+
PUSHER_EVENTS_TYPEBOT_CHANGE_STATUS=false
125+
91126
# WhatsApp Business API - Environment variables
92127
# Token used to validate the webhook on the Facebook APP
93128
WA_BUSINESS_TOKEN_WEBHOOK=evolution

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Fake Call function
66
* Added unreadMessages to chats
7+
* Pusher event integration
78

89
### Fixed
910

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"pg": "^8.11.3",
8383
"pino": "^8.11.0",
8484
"prisma": "^5.15.0",
85+
"pusher": "^5.2.0",
8586
"qrcode": "^1.5.1",
8687
"qrcode-terminal": "^0.12.0",
8788
"redis": "^4.6.5",

prisma/mysql-schema.prisma

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ model Instance {
104104
EvolutionBotSetting EvolutionBotSetting?
105105
Flowise Flowise[]
106106
FlowiseSetting FlowiseSetting?
107+
Pusher Pusher?
107108
}
108109

109110
model Session {
@@ -289,6 +290,21 @@ model Websocket {
289290
instanceId String @unique
290291
}
291292

293+
model Pusher {
294+
id String @id @default(cuid())
295+
enabled Boolean @default(false)
296+
appId String @db.VarChar(100)
297+
key String @db.VarChar(100)
298+
secret String @db.VarChar(100)
299+
cluster String @db.VarChar(100)
300+
useTLS Boolean @default(false)
301+
events Json @db.Json
302+
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
303+
updatedAt DateTime @updatedAt @db.Timestamp
304+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
305+
instanceId String @unique
306+
}
307+
292308
model Typebot {
293309
id String @id @default(cuid())
294310
enabled Boolean @default(true)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- CreateTable
2+
CREATE TABLE "Pusher" (
3+
"id" TEXT NOT NULL,
4+
"enabled" BOOLEAN NOT NULL DEFAULT false,
5+
"appId" VARCHAR(100) NOT NULL,
6+
"key" VARCHAR(100) NOT NULL,
7+
"secret" VARCHAR(100) NOT NULL,
8+
"cluster" VARCHAR(100) NOT NULL,
9+
"useTLS" BOOLEAN NOT NULL DEFAULT false,
10+
"events" JSONB NOT NULL,
11+
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
12+
"updatedAt" TIMESTAMP NOT NULL,
13+
"instanceId" TEXT NOT NULL,
14+
15+
CONSTRAINT "Pusher_pkey" PRIMARY KEY ("id")
16+
);
17+
18+
-- CreateIndex
19+
CREATE UNIQUE INDEX "Pusher_instanceId_key" ON "Pusher"("instanceId");
20+
21+
-- AddForeignKey
22+
ALTER TABLE "Pusher" ADD CONSTRAINT "Pusher_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/postgresql-schema.prisma

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ model Instance {
104104
EvolutionBotSetting EvolutionBotSetting?
105105
Flowise Flowise[]
106106
FlowiseSetting FlowiseSetting?
107+
Pusher Pusher?
107108
}
108109

109110
model Session {
@@ -115,15 +116,15 @@ model Session {
115116
}
116117

117118
model Chat {
118-
id String @id @default(cuid())
119-
remoteJid String @db.VarChar(100)
120-
name String? @db.VarChar(100)
121-
labels Json? @db.JsonB
122-
createdAt DateTime? @default(now()) @db.Timestamp
123-
updatedAt DateTime? @updatedAt @db.Timestamp
124-
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
125-
instanceId String
126-
unreadMessages Int @default(0)
119+
id String @id @default(cuid())
120+
remoteJid String @db.VarChar(100)
121+
name String? @db.VarChar(100)
122+
labels Json? @db.JsonB
123+
createdAt DateTime? @default(now()) @db.Timestamp
124+
updatedAt DateTime? @updatedAt @db.Timestamp
125+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
126+
instanceId String
127+
unreadMessages Int @default(0)
127128
}
128129

129130
model Contact {
@@ -291,6 +292,21 @@ model Websocket {
291292
instanceId String @unique
292293
}
293294

295+
model Pusher {
296+
id String @id @default(cuid())
297+
enabled Boolean @default(false) @db.Boolean
298+
appId String @db.VarChar(100)
299+
key String @db.VarChar(100)
300+
secret String @db.VarChar(100)
301+
cluster String @db.VarChar(100)
302+
useTLS Boolean @default(false) @db.Boolean
303+
events Json @db.JsonB
304+
createdAt DateTime? @default(now()) @db.Timestamp
305+
updatedAt DateTime @updatedAt @db.Timestamp
306+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
307+
instanceId String @unique
308+
}
309+
294310
model Typebot {
295311
id String @id @default(cuid())
296312
enabled Boolean @default(true) @db.Boolean

src/api/integrations/event/event.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type EmitData = {
77
instanceName: string;
88
origin: string;
99
event: string;
10-
data: Object;
10+
data: any;
1111
serverUrl: string;
1212
dateTime: string;
1313
sender: string;
@@ -22,7 +22,7 @@ export interface EventControllerInterface {
2222
}
2323

2424
export class EventController {
25-
private prismaRepository: PrismaRepository;
25+
public prismaRepository: PrismaRepository;
2626
private waMonitor: WAMonitoringService;
2727
private integrationStatus: boolean;
2828
private integrationName: string;

src/api/integrations/event/event.dto.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export class EventDto {
2525
enabled?: boolean;
2626
events?: string[];
2727
};
28+
29+
pusher?: {
30+
enabled?: boolean;
31+
appId?: string;
32+
key?: string;
33+
secret?: string;
34+
cluster?: string;
35+
useTLS?: boolean;
36+
events?: string[];
37+
};
2838
}
2939

3040
export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
@@ -52,5 +62,15 @@ export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
5262
enabled?: boolean;
5363
events?: string[];
5464
};
65+
66+
pusher?: {
67+
enabled?: boolean;
68+
appId?: string;
69+
key?: string;
70+
secret?: string;
71+
cluster?: string;
72+
useTLS?: boolean;
73+
events?: string[];
74+
};
5575
};
5676
}

src/api/integrations/event/event.manager.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PusherController } from '@api/integrations/event/pusher/pusher.controller';
12
import { RabbitmqController } from '@api/integrations/event/rabbitmq/rabbitmq.controller';
23
import { SqsController } from '@api/integrations/event/sqs/sqs.controller';
34
import { WebhookController } from '@api/integrations/event/webhook/webhook.controller';
@@ -13,6 +14,7 @@ export class EventManager {
1314
private webhookController: WebhookController;
1415
private rabbitmqController: RabbitmqController;
1516
private sqsController: SqsController;
17+
private pusherController: PusherController;
1618

1719
constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) {
1820
this.prisma = prismaRepository;
@@ -22,6 +24,7 @@ export class EventManager {
2224
this.webhook = new WebhookController(prismaRepository, waMonitor);
2325
this.rabbitmq = new RabbitmqController(prismaRepository, waMonitor);
2426
this.sqs = new SqsController(prismaRepository, waMonitor);
27+
this.pusher = new PusherController(prismaRepository, waMonitor);
2528
}
2629

2730
public set prisma(prisma: PrismaRepository) {
@@ -72,10 +75,18 @@ export class EventManager {
7275
return this.sqsController;
7376
}
7477

78+
public set pusher(pusher: PusherController) {
79+
this.pusherController = pusher;
80+
}
81+
public get pusher() {
82+
return this.pusherController;
83+
}
84+
7585
public init(httpServer: Server): void {
7686
this.websocket.init(httpServer);
7787
this.rabbitmq.init();
7888
this.sqs.init();
89+
this.pusher.init();
7990
}
8091

8192
public async emit(eventData: {
@@ -93,6 +104,7 @@ export class EventManager {
93104
await this.rabbitmq.emit(eventData);
94105
await this.sqs.emit(eventData);
95106
await this.webhook.emit(eventData);
107+
await this.pusher.emit(eventData);
96108
}
97109

98110
public async setInstance(instanceName: string, data: any): Promise<any> {
@@ -131,5 +143,18 @@ export class EventManager {
131143
byEvents: data.webhook?.byEvents,
132144
},
133145
});
146+
147+
if (data.pusher)
148+
await this.pusher.set(instanceName, {
149+
pusher: {
150+
enabled: true,
151+
events: data.pusher?.events,
152+
appId: data.pusher?.appId,
153+
key: data.pusher?.key,
154+
secret: data.pusher?.secret,
155+
cluster: data.pusher?.cluster,
156+
useTLS: data.pusher?.useTLS,
157+
},
158+
});
134159
}
135160
}

src/api/integrations/event/event.router.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PusherRouter } from '@api/integrations/event/pusher/pusher.router';
12
import { RabbitmqRouter } from '@api/integrations/event/rabbitmq/rabbitmq.router';
23
import { SqsRouter } from '@api/integrations/event/sqs/sqs.router';
34
import { WebhookRouter } from '@api/integrations/event/webhook/webhook.router';
@@ -13,6 +14,7 @@ export class EventRouter {
1314
this.router.use('/webhook', new WebhookRouter(configService, ...guards).router);
1415
this.router.use('/websocket', new WebsocketRouter(...guards).router);
1516
this.router.use('/rabbitmq', new RabbitmqRouter(...guards).router);
17+
this.router.use('/pusher', new PusherRouter(...guards).router);
1618
this.router.use('/sqs', new SqsRouter(...guards).router);
1719
}
1820
}

0 commit comments

Comments
 (0)