mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-19 17:59:12 -06:00
chore: Update telemetry and add new integrations
Refactored the telemetry guard to use a new sendTelemetry utility function, which allows for easier tracking of API routes. Also, added telemetry events for message sending in the Chatwoot and Typebot services. Additionally, updated the README.md to include new content creators and added new integrations with Typebot and Chatwoot services. Modified: - README.md - package.json - src/api/guards/telemetry.guard.ts - src/api/integrations/chatwoot/services/chatwoot.service.ts - src/api/integrations/typebot/services/typebot.service.ts Added: - src/utils/sendTelemetry.ts
This commit is contained in:
parent
22a24b1b88
commit
a03ce984f6
@ -172,3 +172,6 @@ We are proud to collaborate with the following content creators who have contrib
|
|||||||
- [Costar Wagner Dev](https://www.youtube.com/@costarwagnerdev)
|
- [Costar Wagner Dev](https://www.youtube.com/@costarwagnerdev)
|
||||||
- [Dante Testa](https://youtube.com/@dantetesta_)
|
- [Dante Testa](https://youtube.com/@dantetesta_)
|
||||||
- [Rubén Salazar](https://youtube.com/channel/UCnYGZIE2riiLqaN9sI6riig)
|
- [Rubén Salazar](https://youtube.com/channel/UCnYGZIE2riiLqaN9sI6riig)
|
||||||
|
- [OrionDesign](youtube.com/OrionDesign_Oficial)
|
||||||
|
- [IMPA 365](youtube.com/@impa365_ofc)
|
||||||
|
- [Comunidade Hub Connect](https://youtube.com/@comunidadehubconnect)
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "2.0.0",
|
"version": "2.0.0-beta",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,29 +1,10 @@
|
|||||||
import axios from 'axios';
|
|
||||||
import { NextFunction, Request, Response } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
import { sendTelemetry } from '../../utils/sendTelemetry';
|
||||||
|
|
||||||
interface TelemetryData {
|
|
||||||
route: string;
|
|
||||||
apiVersion: string;
|
|
||||||
timestamp: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Telemetry {
|
class Telemetry {
|
||||||
public collectTelemetry(req: Request, res: Response, next: NextFunction): void {
|
public collectTelemetry(req: Request, res: Response, next: NextFunction): void {
|
||||||
const telemetry: TelemetryData = {
|
sendTelemetry(req.path);
|
||||||
route: req.path,
|
|
||||||
apiVersion: `${packageJson.version}`,
|
|
||||||
timestamp: new Date(),
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
|
||||||
.post('https://log.evolution-api.com/telemetry', telemetry)
|
|
||||||
.then(() => {})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Telemetry error', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import { Readable } from 'stream';
|
|||||||
import { Chatwoot, ConfigService, HttpServer } from '../../../../config/env.config';
|
import { Chatwoot, ConfigService, HttpServer } from '../../../../config/env.config';
|
||||||
import { Logger } from '../../../../config/logger.config';
|
import { Logger } from '../../../../config/logger.config';
|
||||||
import i18next from '../../../../utils/i18n';
|
import i18next from '../../../../utils/i18n';
|
||||||
|
import { sendTelemetry } from '../../../../utils/sendTelemetry';
|
||||||
import { ICache } from '../../../abstract/abstract.cache';
|
import { ICache } from '../../../abstract/abstract.cache';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../../../dto/sendMessage.dto';
|
import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../../../dto/sendMessage.dto';
|
||||||
@ -1034,6 +1035,8 @@ export class ChatwootService {
|
|||||||
quoted: options?.quoted,
|
quoted: options?.quoted,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendWhatsAppAudio');
|
||||||
|
|
||||||
const messageSent = await waInstance?.audioWhatsapp(data, true);
|
const messageSent = await waInstance?.audioWhatsapp(data, true);
|
||||||
|
|
||||||
return messageSent;
|
return messageSent;
|
||||||
@ -1052,6 +1055,8 @@ export class ChatwootService {
|
|||||||
quoted: options?.quoted,
|
quoted: options?.quoted,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendMedia');
|
||||||
|
|
||||||
if (caption) {
|
if (caption) {
|
||||||
data.caption = caption;
|
data.caption = caption;
|
||||||
}
|
}
|
||||||
@ -1290,6 +1295,8 @@ export class ChatwootService {
|
|||||||
quoted: await this.getQuotedMessage(body, instance),
|
quoted: await this.getQuotedMessage(body, instance),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
|
|
||||||
let messageSent: any;
|
let messageSent: any;
|
||||||
try {
|
try {
|
||||||
messageSent = await waInstance?.textMessage(data, true);
|
messageSent = await waInstance?.textMessage(data, true);
|
||||||
@ -1380,6 +1387,8 @@ export class ChatwootService {
|
|||||||
delay: 1200,
|
delay: 1200,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
|
|
||||||
await waInstance?.textMessage(data);
|
await waInstance?.textMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import axios from 'axios';
|
|||||||
|
|
||||||
import { ConfigService, S3, Typebot } from '../../../../config/env.config';
|
import { ConfigService, S3, Typebot } from '../../../../config/env.config';
|
||||||
import { Logger } from '../../../../config/logger.config';
|
import { Logger } from '../../../../config/logger.config';
|
||||||
|
import { sendTelemetry } from '../../../../utils/sendTelemetry';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { PrismaRepository } from '../../../repository/repository.service';
|
import { PrismaRepository } from '../../../repository/repository.service';
|
||||||
import { WAMonitoringService } from '../../../services/monitor.service';
|
import { WAMonitoringService } from '../../../services/monitor.service';
|
||||||
@ -1091,6 +1092,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'image') {
|
if (message.type === 'image') {
|
||||||
@ -1103,6 +1106,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendMedia');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'video') {
|
if (message.type === 'video') {
|
||||||
@ -1115,6 +1120,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendMedia');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'audio') {
|
if (message.type === 'audio') {
|
||||||
@ -1127,6 +1134,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendWhatsAppAudio');
|
||||||
}
|
}
|
||||||
|
|
||||||
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
||||||
@ -1156,6 +1165,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
}
|
}
|
||||||
|
|
||||||
await prismaRepository.typebotSession.update({
|
await prismaRepository.typebotSession.update({
|
||||||
@ -1588,6 +1599,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1700,6 +1713,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1779,6 +1794,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendTelemetry('/message/sendText');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
25
src/utils/sendTelemetry.ts
Normal file
25
src/utils/sendTelemetry.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
|
|
||||||
|
export interface TelemetryData {
|
||||||
|
route: string;
|
||||||
|
apiVersion: string;
|
||||||
|
timestamp: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sendTelemetry = async (route: string): Promise<void> => {
|
||||||
|
const telemetry: TelemetryData = {
|
||||||
|
route,
|
||||||
|
apiVersion: `${packageJson.version}`,
|
||||||
|
timestamp: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post('https://log.evolution-api.com/telemetry', telemetry)
|
||||||
|
.then(() => {})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Telemetry error', error);
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user