mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
Merge pull request #986 from deivisonrpg/refactor-onSendMessageError
refactor: Remove unnecessary code for handling contact not in WhatsApp and onSendMessageError
This commit is contained in:
commit
b18e83d293
@ -1898,17 +1898,6 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
|
||||
|
||||
if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) {
|
||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
|
||||
const body = {
|
||||
key: { remoteJid: isWA.jid },
|
||||
};
|
||||
|
||||
this.chatwootService.eventWhatsapp(
|
||||
'contact.is_not_in_wpp',
|
||||
{ instanceName: this.instance.name, instanceId: this.instance.id },
|
||||
body,
|
||||
);
|
||||
}
|
||||
throw new BadRequestException(isWA);
|
||||
}
|
||||
|
||||
|
@ -1137,19 +1137,35 @@ export class ChatwootService {
|
||||
}
|
||||
}
|
||||
|
||||
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: string) {
|
||||
public async onSendMessageError(instance: InstanceDto, conversation: number, error?: any) {
|
||||
this.logger.verbose(`onSendMessageError ${JSON.stringify(error)}`);
|
||||
|
||||
const client = await this.clientCw(instance);
|
||||
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (error && error?.status === 400 && error?.message[0]?.exists === false) {
|
||||
client.messages.create({
|
||||
accountId: this.provider.accountId,
|
||||
conversationId: conversation,
|
||||
data: {
|
||||
content: `${i18next.t('cw.message.numbernotinwhatsapp')}`,
|
||||
message_type: 'outgoing',
|
||||
private: true,
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
client.messages.create({
|
||||
accountId: this.provider.accountId,
|
||||
conversationId: conversation,
|
||||
data: {
|
||||
content: i18next.t('cw.message.notsent', {
|
||||
error: error?.length > 0 ? `_${error}_` : '',
|
||||
error: error ? `_${error.toString()}_` : '',
|
||||
}),
|
||||
message_type: 'outgoing',
|
||||
private: true,
|
||||
@ -1393,7 +1409,7 @@ export class ChatwootService {
|
||||
);
|
||||
} catch (error) {
|
||||
if (!messageSent && body.conversation?.id) {
|
||||
this.onSendMessageError(instance, body.conversation?.id, error.toString());
|
||||
this.onSendMessageError(instance, body.conversation?.id, error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@ -1853,27 +1869,6 @@ export class ChatwootService {
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'contact.is_not_in_wpp') {
|
||||
const getConversation = await this.createConversation(instance, body);
|
||||
|
||||
if (!getConversation) {
|
||||
this.logger.warn('conversation not found');
|
||||
return;
|
||||
}
|
||||
|
||||
client.messages.create({
|
||||
accountId: this.provider.accountId,
|
||||
conversationId: getConversation,
|
||||
data: {
|
||||
content: `🚨 ${i18next.t('numbernotinwhatsapp')}`,
|
||||
message_type: 'outgoing',
|
||||
private: true,
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event === 'messages.upsert' || event === 'send.message') {
|
||||
if (body.key.remoteJid === 'status@broadcast') {
|
||||
return;
|
||||
|
@ -2,7 +2,6 @@
|
||||
"qrgeneratedsuccesfully": "QRCode successfully generated!",
|
||||
"scanqr": "Scan this QR code within the next 40 seconds.",
|
||||
"qrlimitreached": "QRCode generation limit reached, to generate a new QRCode, send the 'init' message again.",
|
||||
"numbernotinwhatsapp": "The message was not sent as the contact is not a valid Whatsapp number.",
|
||||
"cw.inbox.connected": "🚀 Connection successfully established!",
|
||||
"cw.inbox.disconnect": "🚨 Disconnecting WhatsApp from inbox *{{inboxName}}*.",
|
||||
"cw.inbox.alreadyConnected": "🚨 {{inboxName}} instance is connected.",
|
||||
@ -23,5 +22,6 @@
|
||||
"cw.contactMessage.name": "Name",
|
||||
"cw.contactMessage.number": "Number",
|
||||
"cw.message.notsent": "🚨 The message could not be sent. Please check your connection. {{error}}",
|
||||
"cw.message.numbernotinwhatsapp": "🚨 The message was not sent as the contact is not a valid Whatsapp number.",
|
||||
"cw.message.edited": "Edited Message"
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
"qrgeneratedsuccesfully": "Código QR generado exitosamente!",
|
||||
"scanqr": "Escanea este código QR en los próximos 40 segundos.",
|
||||
"qrlimitreached": "🚨 Se alcanzó el límite de generación de QRCode. Para generar un nuevo QRCode, envíe el mensaje 'init' nuevamente.",
|
||||
"numbernotinwhatsapp": "⚠️ El mensaje no fue enviado porque el contacto no es un número de Whatsapp válido..",
|
||||
"cw.inbox.connected": "🚀 ¡Conexión establecida exitosamente!",
|
||||
"cw.inbox.disconnect": "🚨 Instancia *{{inboxName}}* desconectado de Whatsapp.",
|
||||
"cw.inbox.alreadyConnected": "🚨 La instancia {{inboxName}} está conectada.",
|
||||
@ -23,5 +22,6 @@
|
||||
"cw.contactMessage.name": "Nombre",
|
||||
"cw.contactMessage.number": "Numero",
|
||||
"cw.message.notsent": "🚨 El mensaje no se pudo enviar. Comprueba tu conexión. {{error}}",
|
||||
"cw.message.numbernotinwhatsapp": "🚨 El mensaje no fue enviado porque el contacto no es un número de Whatsapp válido.",
|
||||
"cw.message.edited": "Mensaje editado"
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
"qrgeneratedsuccesfully": "QRCode gerado com sucesso!",
|
||||
"scanqr": "Escaneie o QRCode com o WhatsApp nos próximos 40 segundos.",
|
||||
"qrlimitreached": "Limite de geração de QRCode atingido! Para gerar um novo QRCode, envie o texto 'init' nesta conversa.",
|
||||
"numbernotinwhatsapp": "A mensagem não foi enviada, pois o contato não é um número válido do WhatsApp.",
|
||||
"cw.inbox.connected": "🚀 Conectado com sucesso!",
|
||||
"cw.inbox.disconnect": "🚨 Instância *{{inboxName}}* desconectada do WhatsApp.",
|
||||
"cw.inbox.alreadyConnected": "🚨 Instância *{{inboxName}}* já está conectada.",
|
||||
@ -23,5 +22,6 @@
|
||||
"cw.contactMessage.name": "Nome",
|
||||
"cw.contactMessage.number": "Número",
|
||||
"cw.message.notsent": "🚨 Não foi possível enviar a mensagem. Verifique sua conexão. {{error}}",
|
||||
"cw.message.numbernotinwhatsapp": "🚨 A mensagem não foi enviada, pois o contato não é um número válido do WhatsApp.",
|
||||
"cw.message.edited": "Mensagem editada"
|
||||
}
|
Loading…
Reference in New Issue
Block a user