@@ -9,10 +9,10 @@ import {
9
9
CallEventWithIntegrationEntities ,
10
10
Contact ,
11
11
ContactCache ,
12
+ ContactChangeEvent ,
12
13
ContactDelta ,
13
14
ContactTemplate ,
14
15
ContactUpdate ,
15
- ContactsChangedData ,
16
16
ServerError ,
17
17
} from '.' ;
18
18
import { calendarEventsSchema , contactsSchema } from '../schemas' ;
@@ -36,6 +36,7 @@ import {
36
36
PubSubContactsState ,
37
37
} from './pubsub-contacts-message.model' ;
38
38
import { PubSubContactsChangedClient } from './pubsub-contacts-changed-client.model' ;
39
+ import { PubSubContactChangeEventMessage } from './pubsub-contacts-changed-message.model' ;
39
40
40
41
const CONTACT_FETCH_TIMEOUT = 5000 ;
41
42
@@ -1354,7 +1355,11 @@ export class Controller {
1354
1355
}
1355
1356
}
1356
1357
1357
- public async handleWebhook ( req : Request , res : Response ) : Promise < void > {
1358
+ public async handleWebhook (
1359
+ req : Request ,
1360
+ res : Response ,
1361
+ next : NextFunction ,
1362
+ ) : Promise < void > {
1358
1363
if ( ! this . adapter . handleWebhook ) {
1359
1364
throw new ServerError ( 501 , 'Webhook handling not implemented' ) ;
1360
1365
}
@@ -1371,16 +1376,29 @@ export class Controller {
1371
1376
infoLogger ( 'handleWebhook' , 'START' , '' ) ;
1372
1377
1373
1378
try {
1374
- const contactsChangedData : ContactsChangedData =
1379
+ const changeEvents : ContactChangeEvent [ ] =
1375
1380
await this . adapter . handleWebhook ( req ) ;
1376
1381
1377
1382
infoLogger (
1378
1383
'handleWebhook' ,
1379
- `Got ${ contactsChangedData . data . length } changed contacts` ,
1384
+ `Got ${ changeEvents . length } changed contacts` ,
1380
1385
'' ,
1381
1386
) ;
1382
1387
1383
- this . pubSubContactsChangedClient ?. publishMessage ( contactsChangedData ) ;
1388
+ changeEvents . map ( ( changeEvent : ContactChangeEvent ) => {
1389
+ infoLogger (
1390
+ 'handleWebhook' ,
1391
+ `Publishing contact change event with accountId ${ changeEvent . accountId } and contactId ${ changeEvent . contactId } ` ,
1392
+ '' ,
1393
+ ) ;
1394
+
1395
+ const message : PubSubContactChangeEventMessage = {
1396
+ integrationName : this . integrationName ,
1397
+ ...changeEvent ,
1398
+ } ;
1399
+
1400
+ this . pubSubContactsChangedClient ?. publishMessage ( message ) ;
1401
+ } ) ;
1384
1402
1385
1403
infoLogger ( 'handleWebhook' , 'END' , '' ) ;
1386
1404
res . sendStatus ( 200 ) ;
@@ -1391,7 +1409,7 @@ export class Controller {
1391
1409
'' ,
1392
1410
error || 'Unknown' ,
1393
1411
) ;
1394
- res . sendStatus ( 500 ) ;
1412
+ next ( error ) ;
1395
1413
}
1396
1414
}
1397
1415
}
0 commit comments