mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-21 03:27:22 -06:00
feat: Send contact in chatwoot
This commit is contained in:
parent
c1226062b1
commit
0db8f7295b
@ -21,6 +21,7 @@
|
|||||||
* Fixed bug that saved contacts from groups came without number in chatwoot
|
* Fixed bug that saved contacts from groups came without number in chatwoot
|
||||||
* Fixed problem to receive csat in chatwoot
|
* Fixed problem to receive csat in chatwoot
|
||||||
* Fixed require fileName for document only in base64 for send media message
|
* Fixed require fileName for document only in base64 for send media message
|
||||||
|
* Bug fix when sending mobile message change contact name to number in chatwoot
|
||||||
|
|
||||||
# 1.2.2 (2023-07-15 09:36)
|
# 1.2.2 (2023-07-15 09:36)
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
||||||
"@figuro/chatwoot-sdk": "^1.1.14",
|
"@figuro/chatwoot-sdk": "^1.1.14",
|
||||||
"@hapi/boom": "^10.0.1",
|
"@hapi/boom": "^10.0.1",
|
||||||
|
"@sentry/node": "^7.59.2",
|
||||||
"@whiskeysockets/baileys": "^6.4.0",
|
"@whiskeysockets/baileys": "^6.4.0",
|
||||||
"axios": "^1.3.5",
|
"axios": "^1.3.5",
|
||||||
"class-validator": "^0.13.2",
|
"class-validator": "^0.13.2",
|
||||||
|
29
src/main.ts
29
src/main.ts
@ -10,6 +10,7 @@ import { waMonitor } from './whatsapp/whatsapp.module';
|
|||||||
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
import { HttpStatus, router } from './whatsapp/routers/index.router';
|
||||||
import 'express-async-errors';
|
import 'express-async-errors';
|
||||||
import { ServerUP } from './utils/server-up';
|
import { ServerUP } from './utils/server-up';
|
||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
|
||||||
function initWA() {
|
function initWA() {
|
||||||
waMonitor.loadInstance();
|
waMonitor.loadInstance();
|
||||||
@ -19,6 +20,27 @@ function bootstrap() {
|
|||||||
const logger = new Logger('SERVER');
|
const logger = new Logger('SERVER');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
// Sentry.init({
|
||||||
|
// dsn: '',
|
||||||
|
// integrations: [
|
||||||
|
// // enable HTTP calls tracing
|
||||||
|
// new Sentry.Integrations.Http({ tracing: true }),
|
||||||
|
// // enable Express.js middleware tracing
|
||||||
|
// new Sentry.Integrations.Express({ app }),
|
||||||
|
// // Automatically instrument Node.js libraries and frameworks
|
||||||
|
// ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
|
||||||
|
// ],
|
||||||
|
|
||||||
|
// // Set tracesSampleRate to 1.0 to capture 100%
|
||||||
|
// // of transactions for performance monitoring.
|
||||||
|
// // We recommend adjusting this value in production
|
||||||
|
// tracesSampleRate: 1.0,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.requestHandler());
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.tracingHandler());
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin(requestOrigin, callback) {
|
origin(requestOrigin, callback) {
|
||||||
@ -43,6 +65,13 @@ function bootstrap() {
|
|||||||
|
|
||||||
app.use('/', router);
|
app.use('/', router);
|
||||||
|
|
||||||
|
// app.use(Sentry.Handlers.errorHandler());
|
||||||
|
|
||||||
|
// app.use(function onError(err, req, res, next) {
|
||||||
|
// res.statusCode = 500;
|
||||||
|
// res.end(res.sentry + '\n');
|
||||||
|
// });
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
(err: Error, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -453,21 +453,24 @@ export class ChatwootService {
|
|||||||
const findContact = await this.findContact(instance, chatId);
|
const findContact = await this.findContact(instance, chatId);
|
||||||
|
|
||||||
let contact: any;
|
let contact: any;
|
||||||
|
if (body.key.fromMe) {
|
||||||
if (findContact) {
|
contact = findContact;
|
||||||
contact = await this.updateContact(instance, findContact.id, {
|
|
||||||
name: nameContact,
|
|
||||||
avatar_url: picture_url.profilePictureUrl || null,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
contact = await this.createContact(
|
if (findContact) {
|
||||||
instance,
|
contact = await this.updateContact(instance, findContact.id, {
|
||||||
chatId,
|
name: nameContact,
|
||||||
filterInbox.id,
|
avatar_url: picture_url.profilePictureUrl || null,
|
||||||
isGroup,
|
});
|
||||||
nameContact,
|
} else {
|
||||||
picture_url.profilePictureUrl || null,
|
contact = await this.createContact(
|
||||||
);
|
instance,
|
||||||
|
chatId,
|
||||||
|
filterInbox.id,
|
||||||
|
isGroup,
|
||||||
|
nameContact,
|
||||||
|
picture_url.profilePictureUrl || null,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
@ -475,7 +478,8 @@ export class ChatwootService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contactId = contact.payload.id || contact.payload.contact.id;
|
const contactId =
|
||||||
|
contact?.payload?.id || contact?.payload?.contact?.id || contact?.id;
|
||||||
|
|
||||||
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
|
if (!body.key.fromMe && contact.name === chatId && nameContact !== chatId) {
|
||||||
this.logger.verbose('update contact name in chatwoot');
|
this.logger.verbose('update contact name in chatwoot');
|
||||||
@ -987,13 +991,9 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.includes('#inbox_whatsapp')) {
|
if (command.includes('#inbox_whatsapp')) {
|
||||||
console.log('command include #inbox_whatsapp');
|
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
const apiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY;
|
||||||
|
|
||||||
console.log('url server: ' + urlServer);
|
|
||||||
console.log('api key: ' + apiKey);
|
|
||||||
const data = {
|
const data = {
|
||||||
instanceName: command.split(':')[1],
|
instanceName: command.split(':')[1],
|
||||||
qrcode: true,
|
qrcode: true,
|
||||||
@ -1014,9 +1014,7 @@ export class ChatwootService {
|
|||||||
data: data,
|
data: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: response } = await axios.request(config);
|
await axios.request(config);
|
||||||
|
|
||||||
console.log(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1101,7 +1099,6 @@ export class ChatwootService {
|
|||||||
body.content_type === 'input_csat' &&
|
body.content_type === 'input_csat' &&
|
||||||
body.event === 'message_created'
|
body.event === 'message_created'
|
||||||
) {
|
) {
|
||||||
console.log(body);
|
|
||||||
this.logger.verbose('check if is csat');
|
this.logger.verbose('check if is csat');
|
||||||
|
|
||||||
const data: SendTextDto = {
|
const data: SendTextDto = {
|
||||||
@ -1161,6 +1158,7 @@ export class ChatwootService {
|
|||||||
documentWithCaptionMessage:
|
documentWithCaptionMessage:
|
||||||
msg.documentWithCaptionMessage?.message?.documentMessage?.caption,
|
msg.documentWithCaptionMessage?.message?.documentMessage?.caption,
|
||||||
audioMessage: msg.audioMessage?.caption,
|
audioMessage: msg.audioMessage?.caption,
|
||||||
|
contactMessage: msg.contactMessage?.vcard,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.verbose('type message: ' + types);
|
this.logger.verbose('type message: ' + types);
|
||||||
@ -1174,6 +1172,25 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const result = typeKey ? types[typeKey] : undefined;
|
const result = typeKey ? types[typeKey] : undefined;
|
||||||
|
|
||||||
|
if (typeKey === 'contactMessage') {
|
||||||
|
const vCardData = result.split('\n');
|
||||||
|
const contactInfo = {};
|
||||||
|
|
||||||
|
vCardData.forEach((line) => {
|
||||||
|
const [key, value] = line.split(':');
|
||||||
|
if (key && value) {
|
||||||
|
contactInfo[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const formattedContact = `**Contact:**
|
||||||
|
**name:** ${contactInfo['FN']}
|
||||||
|
**number:** ${contactInfo['item1.TEL;waid=5511952801378']}`;
|
||||||
|
|
||||||
|
this.logger.verbose('message content: ' + formattedContact);
|
||||||
|
return formattedContact;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.verbose('message content: ' + result);
|
this.logger.verbose('message content: ' + result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -1184,8 +1201,12 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const types = this.getTypeMessage(msg);
|
const types = this.getTypeMessage(msg);
|
||||||
|
|
||||||
|
console.log('types', types);
|
||||||
|
|
||||||
const messageContent = this.getMessageContent(types);
|
const messageContent = this.getMessageContent(types);
|
||||||
|
|
||||||
|
console.log('messageContent', messageContent);
|
||||||
|
|
||||||
this.logger.verbose('conversation message: ' + messageContent);
|
this.logger.verbose('conversation message: ' + messageContent);
|
||||||
|
|
||||||
return messageContent;
|
return messageContent;
|
||||||
|
Loading…
Reference in New Issue
Block a user