mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
Merge branch 'release/1.4.4'
This commit is contained in:
commit
2b6dbfde6b
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
# 1.4.4 (2023-07-25 15:24)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed chatwoot line wrap issue
|
||||||
|
* Solved receive location in chatwoot
|
||||||
|
* When requesting the pairing code, it also brings the qr code
|
||||||
|
* Option reopen_conversation in chatwoot endpoint
|
||||||
|
* Option conversation_pending in chatwoot endpoint
|
||||||
|
|
||||||
# 1.4.3 (2023-07-25 10:51)
|
# 1.4.3 (2023-07-25 10:51)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"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": {
|
||||||
|
@ -874,9 +874,26 @@ export const chatwootSchema: JSONSchema7 = {
|
|||||||
token: { type: 'string' },
|
token: { type: 'string' },
|
||||||
url: { type: 'string' },
|
url: { type: 'string' },
|
||||||
sign_msg: { type: 'boolean', enum: [true, false] },
|
sign_msg: { type: 'boolean', enum: [true, false] },
|
||||||
|
reopen_conversation: { type: 'boolean', enum: [true, false] },
|
||||||
|
conversation_pending: { type: 'boolean', enum: [true, false] },
|
||||||
},
|
},
|
||||||
required: ['enabled', 'account_id', 'token', 'url', 'sign_msg'],
|
required: [
|
||||||
...isNotEmpty('account_id', 'token', 'url', 'sign_msg'),
|
'enabled',
|
||||||
|
'account_id',
|
||||||
|
'token',
|
||||||
|
'url',
|
||||||
|
'sign_msg',
|
||||||
|
'reopen_conversation',
|
||||||
|
'conversation_pending',
|
||||||
|
],
|
||||||
|
...isNotEmpty(
|
||||||
|
'account_id',
|
||||||
|
'token',
|
||||||
|
'url',
|
||||||
|
'sign_msg',
|
||||||
|
'reopen_conversation',
|
||||||
|
'conversation_pending',
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const settingsSchema: JSONSchema7 = {
|
export const settingsSchema: JSONSchema7 = {
|
||||||
|
@ -44,6 +44,8 @@ export class ChatwootController {
|
|||||||
data.token = '';
|
data.token = '';
|
||||||
data.url = '';
|
data.url = '';
|
||||||
data.sign_msg = false;
|
data.sign_msg = false;
|
||||||
|
data.reopen_conversation = false;
|
||||||
|
data.conversation_pending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.name_inbox = instance.instanceName;
|
data.name_inbox = instance.instanceName;
|
||||||
|
@ -42,6 +42,8 @@ export class InstanceController {
|
|||||||
chatwoot_token,
|
chatwoot_token,
|
||||||
chatwoot_url,
|
chatwoot_url,
|
||||||
chatwoot_sign_msg,
|
chatwoot_sign_msg,
|
||||||
|
chatwoot_reopen_conversation,
|
||||||
|
chatwoot_conversation_pending,
|
||||||
reject_call,
|
reject_call,
|
||||||
msg_call,
|
msg_call,
|
||||||
groups_ignore,
|
groups_ignore,
|
||||||
@ -169,6 +171,24 @@ export class InstanceController {
|
|||||||
throw new BadRequestException('Invalid "url" property in chatwoot');
|
throw new BadRequestException('Invalid "url" property in chatwoot');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chatwoot_sign_msg !== true && chatwoot_sign_msg !== false) {
|
||||||
|
throw new BadRequestException('sign_msg is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
chatwoot_reopen_conversation !== true &&
|
||||||
|
chatwoot_reopen_conversation !== false
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('reopen_conversation is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
chatwoot_conversation_pending !== true &&
|
||||||
|
chatwoot_conversation_pending !== false
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('conversation_pending is required');
|
||||||
|
}
|
||||||
|
|
||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -180,6 +200,8 @@ export class InstanceController {
|
|||||||
sign_msg: chatwoot_sign_msg || false,
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
name_inbox: instance.instanceName,
|
name_inbox: instance.instanceName,
|
||||||
number,
|
number,
|
||||||
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chatwootService.initInstanceChatwoot(
|
this.chatwootService.initInstanceChatwoot(
|
||||||
@ -209,6 +231,8 @@ export class InstanceController {
|
|||||||
token: chatwoot_token,
|
token: chatwoot_token,
|
||||||
url: chatwoot_url,
|
url: chatwoot_url,
|
||||||
sign_msg: chatwoot_sign_msg || false,
|
sign_msg: chatwoot_sign_msg || false,
|
||||||
|
reopen_conversation: chatwoot_reopen_conversation || false,
|
||||||
|
conversation_pending: chatwoot_conversation_pending || false,
|
||||||
number,
|
number,
|
||||||
name_inbox: instance.instanceName,
|
name_inbox: instance.instanceName,
|
||||||
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
webhook_url: `${urlServer}/chatwoot/webhook/${instance.instanceName}`,
|
||||||
|
@ -6,4 +6,6 @@ export class ChatwootDto {
|
|||||||
name_inbox?: string;
|
name_inbox?: string;
|
||||||
sign_msg?: boolean;
|
sign_msg?: boolean;
|
||||||
number?: string;
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,6 @@ export class InstanceDto {
|
|||||||
chatwoot_token?: string;
|
chatwoot_token?: string;
|
||||||
chatwoot_url?: string;
|
chatwoot_url?: string;
|
||||||
chatwoot_sign_msg?: boolean;
|
chatwoot_sign_msg?: boolean;
|
||||||
|
chatwoot_reopen_conversation?: boolean;
|
||||||
|
chatwoot_conversation_pending?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ export class ChatwootRaw {
|
|||||||
name_inbox?: string;
|
name_inbox?: string;
|
||||||
sign_msg?: boolean;
|
sign_msg?: boolean;
|
||||||
number?: string;
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatwootSchema = new Schema<ChatwootRaw>({
|
const chatwootSchema = new Schema<ChatwootRaw>({
|
||||||
|
@ -13,6 +13,7 @@ import { SendAudioDto } from '../dto/sendMessage.dto';
|
|||||||
import { SendMediaDto } from '../dto/sendMessage.dto';
|
import { SendMediaDto } from '../dto/sendMessage.dto';
|
||||||
import { ROOT_DIR } from '../../config/path.config';
|
import { ROOT_DIR } from '../../config/path.config';
|
||||||
import { ConfigService, HttpServer } from '../../config/env.config';
|
import { ConfigService, HttpServer } from '../../config/env.config';
|
||||||
|
import { type } from 'os';
|
||||||
|
|
||||||
export class ChatwootService {
|
export class ChatwootService {
|
||||||
private messageCacheFile: string;
|
private messageCacheFile: string;
|
||||||
@ -230,12 +231,19 @@ export class ChatwootService {
|
|||||||
|
|
||||||
if (qrcode) {
|
if (qrcode) {
|
||||||
this.logger.verbose('create conversation in chatwoot');
|
this.logger.verbose('create conversation in chatwoot');
|
||||||
const conversation = await client.conversations.create({
|
const data = {
|
||||||
accountId: this.provider.account_id,
|
|
||||||
data: {
|
|
||||||
contact_id: contactId.toString(),
|
contact_id: contactId.toString(),
|
||||||
inbox_id: inboxId.toString(),
|
inbox_id: inboxId.toString(),
|
||||||
},
|
};
|
||||||
|
|
||||||
|
if (this.provider.conversation_pending) {
|
||||||
|
data['status'] = 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('this.provider', this.provider);
|
||||||
|
const conversation = await client.conversations.create({
|
||||||
|
accountId: this.provider.account_id,
|
||||||
|
data,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!conversation) {
|
if (!conversation) {
|
||||||
@ -520,11 +528,20 @@ export class ChatwootService {
|
|||||||
})) as any;
|
})) as any;
|
||||||
|
|
||||||
if (contactConversations) {
|
if (contactConversations) {
|
||||||
this.logger.verbose('return conversation if exists');
|
let conversation: any;
|
||||||
const conversation = contactConversations.payload.find(
|
if (this.provider.reopen_conversation) {
|
||||||
(conversation) =>
|
conversation = contactConversations.payload.find(
|
||||||
conversation.status !== 'resolved' && conversation.inbox_id == filterInbox.id,
|
(conversation) => conversation.inbox_id == filterInbox.id,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
conversation = contactConversations.payload.find(
|
||||||
|
(conversation) =>
|
||||||
|
conversation.status !== 'resolved' &&
|
||||||
|
conversation.inbox_id == filterInbox.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.logger.verbose('return conversation if exists');
|
||||||
|
|
||||||
if (conversation) {
|
if (conversation) {
|
||||||
this.logger.verbose('conversation found');
|
this.logger.verbose('conversation found');
|
||||||
return conversation.id;
|
return conversation.id;
|
||||||
@ -532,12 +549,18 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.verbose('create conversation in chatwoot');
|
this.logger.verbose('create conversation in chatwoot');
|
||||||
|
const data = {
|
||||||
|
contact_id: contactId.toString(),
|
||||||
|
inbox_id: filterInbox.id.toString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.provider.conversation_pending) {
|
||||||
|
data['status'] = 'pending';
|
||||||
|
}
|
||||||
|
|
||||||
const conversation = await client.conversations.create({
|
const conversation = await client.conversations.create({
|
||||||
accountId: this.provider.account_id,
|
accountId: this.provider.account_id,
|
||||||
data: {
|
data,
|
||||||
contact_id: `${contactId}`,
|
|
||||||
inbox_id: `${filterInbox.id}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!conversation) {
|
if (!conversation) {
|
||||||
@ -1125,12 +1148,12 @@ export class ChatwootService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body.message_type === 'template' && body.event === 'message_created') {
|
if (body.message_type === 'template' && body.event === 'message_created') {
|
||||||
this.logger.verbose('check if is csat');
|
this.logger.verbose('check if is template');
|
||||||
|
|
||||||
const data: SendTextDto = {
|
const data: SendTextDto = {
|
||||||
number: chatId,
|
number: chatId,
|
||||||
textMessage: {
|
textMessage: {
|
||||||
text: body.content,
|
text: body.content.replace(/\\\r\n|\\\n|\n/g, '\n'),
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
delay: 1200,
|
delay: 1200,
|
||||||
@ -1186,6 +1209,11 @@ export class ChatwootService {
|
|||||||
audioMessage: msg.audioMessage?.caption,
|
audioMessage: msg.audioMessage?.caption,
|
||||||
contactMessage: msg.contactMessage?.vcard,
|
contactMessage: msg.contactMessage?.vcard,
|
||||||
contactsArrayMessage: msg.contactsArrayMessage,
|
contactsArrayMessage: msg.contactsArrayMessage,
|
||||||
|
locationMessage: !msg.protocolMessage
|
||||||
|
? msg.locationMessage?.degreesLatitude +
|
||||||
|
',' +
|
||||||
|
msg.locationMessage?.degreesLongitude
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.verbose('type message: ' + types);
|
this.logger.verbose('type message: ' + types);
|
||||||
@ -1199,6 +1227,20 @@ export class ChatwootService {
|
|||||||
|
|
||||||
const result = typeKey ? types[typeKey] : undefined;
|
const result = typeKey ? types[typeKey] : undefined;
|
||||||
|
|
||||||
|
if (typeKey === 'locationMessage') {
|
||||||
|
const [latitude, longitude] = result.split(',');
|
||||||
|
|
||||||
|
const formattedLocation = `**Location:**
|
||||||
|
**latitude:** ${latitude}
|
||||||
|
**longitude:** ${longitude}
|
||||||
|
https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}
|
||||||
|
`;
|
||||||
|
|
||||||
|
this.logger.verbose('message content: ' + formattedLocation);
|
||||||
|
|
||||||
|
return formattedLocation;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeKey === 'contactMessage') {
|
if (typeKey === 'contactMessage') {
|
||||||
const vCardData = result.split('\n');
|
const vCardData = result.split('\n');
|
||||||
const contactInfo = {};
|
const contactInfo = {};
|
||||||
|
@ -242,13 +242,9 @@ export class WAStartupService {
|
|||||||
|
|
||||||
public get qrCode(): wa.QrCode {
|
public get qrCode(): wa.QrCode {
|
||||||
this.logger.verbose('Getting qrcode');
|
this.logger.verbose('Getting qrcode');
|
||||||
if (this.instance.qrcode?.pairingCode) {
|
|
||||||
return {
|
|
||||||
pairingCode: this.instance.qrcode?.pairingCode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
pairingCode: this.instance.qrcode?.pairingCode,
|
||||||
code: this.instance.qrcode?.code,
|
code: this.instance.qrcode?.code,
|
||||||
base64: this.instance.qrcode?.base64,
|
base64: this.instance.qrcode?.base64,
|
||||||
};
|
};
|
||||||
@ -316,6 +312,19 @@ export class WAStartupService {
|
|||||||
this.localChatwoot.sign_msg = data?.sign_msg;
|
this.localChatwoot.sign_msg = data?.sign_msg;
|
||||||
this.logger.verbose(`Chatwoot sign msg: ${this.localChatwoot.sign_msg}`);
|
this.logger.verbose(`Chatwoot sign msg: ${this.localChatwoot.sign_msg}`);
|
||||||
|
|
||||||
|
this.localChatwoot.number = data?.number;
|
||||||
|
this.logger.verbose(`Chatwoot number: ${this.localChatwoot.number}`);
|
||||||
|
|
||||||
|
this.localChatwoot.reopen_conversation = data?.reopen_conversation;
|
||||||
|
this.logger.verbose(
|
||||||
|
`Chatwoot reopen conversation: ${this.localChatwoot.reopen_conversation}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.localChatwoot.conversation_pending = data?.conversation_pending;
|
||||||
|
this.logger.verbose(
|
||||||
|
`Chatwoot conversation pending: ${this.localChatwoot.conversation_pending}`,
|
||||||
|
);
|
||||||
|
|
||||||
this.logger.verbose('Chatwoot loaded');
|
this.logger.verbose('Chatwoot loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,6 +336,8 @@ export class WAStartupService {
|
|||||||
this.logger.verbose(`Chatwoot url: ${data.url}`);
|
this.logger.verbose(`Chatwoot url: ${data.url}`);
|
||||||
this.logger.verbose(`Chatwoot inbox name: ${data.name_inbox}`);
|
this.logger.verbose(`Chatwoot inbox name: ${data.name_inbox}`);
|
||||||
this.logger.verbose(`Chatwoot sign msg: ${data.sign_msg}`);
|
this.logger.verbose(`Chatwoot sign msg: ${data.sign_msg}`);
|
||||||
|
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
||||||
|
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
||||||
|
|
||||||
Object.assign(this.localChatwoot, data);
|
Object.assign(this.localChatwoot, data);
|
||||||
this.logger.verbose('Chatwoot set');
|
this.logger.verbose('Chatwoot set');
|
||||||
@ -346,6 +357,8 @@ export class WAStartupService {
|
|||||||
this.logger.verbose(`Chatwoot url: ${data.url}`);
|
this.logger.verbose(`Chatwoot url: ${data.url}`);
|
||||||
this.logger.verbose(`Chatwoot inbox name: ${data.name_inbox}`);
|
this.logger.verbose(`Chatwoot inbox name: ${data.name_inbox}`);
|
||||||
this.logger.verbose(`Chatwoot sign msg: ${data.sign_msg}`);
|
this.logger.verbose(`Chatwoot sign msg: ${data.sign_msg}`);
|
||||||
|
this.logger.verbose(`Chatwoot reopen conversation: ${data.reopen_conversation}`);
|
||||||
|
this.logger.verbose(`Chatwoot conversation pending: ${data.conversation_pending}`);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -622,7 +635,6 @@ export class WAStartupService {
|
|||||||
color: { light: '#ffffff', dark: '#198754' },
|
color: { light: '#ffffff', dark: '#198754' },
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(this.phoneNumber);
|
|
||||||
if (this.phoneNumber) {
|
if (this.phoneNumber) {
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
this.instance.qrcode.pairingCode = await this.client.requestPairingCode(
|
this.instance.qrcode.pairingCode = await this.client.requestPairingCode(
|
||||||
|
@ -56,6 +56,9 @@ export declare namespace wa {
|
|||||||
url?: string;
|
url?: string;
|
||||||
name_inbox?: string;
|
name_inbox?: string;
|
||||||
sign_msg?: boolean;
|
sign_msg?: boolean;
|
||||||
|
number?: string;
|
||||||
|
reopen_conversation?: boolean;
|
||||||
|
conversation_pending?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LocalSettings = {
|
export type LocalSettings = {
|
||||||
|
Loading…
Reference in New Issue
Block a user