mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 12:06:54 -06:00
Merge pull request #739 from fmedeiros95/v2.0.0
Improve reconnection logic for ban and block cases and add disconnection information to BaileysStartupService and Instance model
This commit is contained in:
commit
d0a723b8ef
@ -47,34 +47,37 @@ enum TriggerOperator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Instance {
|
model Instance {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String @unique @db.VarChar(255)
|
name String @unique @db.VarChar(255)
|
||||||
connectionStatus InstanceConnectionStatus @default(open)
|
connectionStatus InstanceConnectionStatus @default(open)
|
||||||
ownerJid String? @db.VarChar(100)
|
ownerJid String? @db.VarChar(100)
|
||||||
profileName String? @db.VarChar(100)
|
profileName String? @db.VarChar(100)
|
||||||
profilePicUrl String? @db.VarChar(500)
|
profilePicUrl String? @db.VarChar(500)
|
||||||
integration String? @db.VarChar(100)
|
integration String? @db.VarChar(100)
|
||||||
number String? @db.VarChar(100)
|
number String? @db.VarChar(100)
|
||||||
token String? @unique @db.VarChar(255)
|
token String? @unique @db.VarChar(255)
|
||||||
clientName String? @db.VarChar(100)
|
clientName String? @db.VarChar(100)
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
disconnectionReasonCode Int? @db.Int
|
||||||
updatedAt DateTime? @updatedAt @db.Timestamp
|
disconnectionObject Json? @db.Json
|
||||||
Chat Chat[]
|
disconnectionAt DateTime? @db.Timestamp
|
||||||
Contact Contact[]
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
Message Message[]
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
||||||
Webhook Webhook?
|
Chat Chat[]
|
||||||
Chatwoot Chatwoot?
|
Contact Contact[]
|
||||||
Label Label[]
|
Message Message[]
|
||||||
Proxy Proxy?
|
Webhook Webhook?
|
||||||
Setting Setting?
|
Chatwoot Chatwoot?
|
||||||
Rabbitmq Rabbitmq?
|
Label Label[]
|
||||||
Sqs Sqs?
|
Proxy Proxy?
|
||||||
Websocket Websocket?
|
Setting Setting?
|
||||||
Typebot Typebot[]
|
Rabbitmq Rabbitmq?
|
||||||
Session Session?
|
Sqs Sqs?
|
||||||
MessageUpdate MessageUpdate[]
|
Websocket Websocket?
|
||||||
TypebotSession TypebotSession[]
|
Typebot Typebot[]
|
||||||
TypebotSetting TypebotSetting?
|
Session Session?
|
||||||
|
MessageUpdate MessageUpdate[]
|
||||||
|
TypebotSession TypebotSession[]
|
||||||
|
TypebotSetting TypebotSetting?
|
||||||
}
|
}
|
||||||
|
|
||||||
model Session {
|
model Session {
|
||||||
|
@ -60,44 +60,47 @@ enum DifyBotType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Instance {
|
model Instance {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String @unique @db.VarChar(255)
|
name String @unique @db.VarChar(255)
|
||||||
connectionStatus InstanceConnectionStatus @default(open)
|
connectionStatus InstanceConnectionStatus @default(open)
|
||||||
ownerJid String? @db.VarChar(100)
|
ownerJid String? @db.VarChar(100)
|
||||||
profileName String? @db.VarChar(100)
|
profileName String? @db.VarChar(100)
|
||||||
profilePicUrl String? @db.VarChar(500)
|
profilePicUrl String? @db.VarChar(500)
|
||||||
integration String? @db.VarChar(100)
|
integration String? @db.VarChar(100)
|
||||||
number String? @db.VarChar(100)
|
number String? @db.VarChar(100)
|
||||||
businessId String? @db.VarChar(100)
|
businessId String? @db.VarChar(100)
|
||||||
token String? @db.VarChar(255)
|
token String? @db.VarChar(255)
|
||||||
clientName String? @db.VarChar(100)
|
clientName String? @db.VarChar(100)
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
disconnectionReasonCode Int? @db.Integer
|
||||||
updatedAt DateTime? @updatedAt @db.Timestamp
|
disconnectionObject Json? @db.JsonB
|
||||||
Chat Chat[]
|
disconnectionAt DateTime? @db.Timestamp
|
||||||
Contact Contact[]
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
Message Message[]
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
||||||
Webhook Webhook?
|
Chat Chat[]
|
||||||
Chatwoot Chatwoot?
|
Contact Contact[]
|
||||||
Label Label[]
|
Message Message[]
|
||||||
Proxy Proxy?
|
Webhook Webhook?
|
||||||
Setting Setting?
|
Chatwoot Chatwoot?
|
||||||
Rabbitmq Rabbitmq?
|
Label Label[]
|
||||||
Sqs Sqs?
|
Proxy Proxy?
|
||||||
Websocket Websocket?
|
Setting Setting?
|
||||||
Typebot Typebot[]
|
Rabbitmq Rabbitmq?
|
||||||
Session Session?
|
Sqs Sqs?
|
||||||
MessageUpdate MessageUpdate[]
|
Websocket Websocket?
|
||||||
TypebotSession TypebotSession[]
|
Typebot Typebot[]
|
||||||
TypebotSetting TypebotSetting?
|
Session Session?
|
||||||
Media Media[]
|
MessageUpdate MessageUpdate[]
|
||||||
OpenaiCreds OpenaiCreds[]
|
TypebotSession TypebotSession[]
|
||||||
OpenaiBot OpenaiBot[]
|
TypebotSetting TypebotSetting?
|
||||||
OpenaiSession OpenaiSession[]
|
Media Media[]
|
||||||
OpenaiSetting OpenaiSetting?
|
OpenaiCreds OpenaiCreds[]
|
||||||
Template Template[]
|
OpenaiBot OpenaiBot[]
|
||||||
Dify Dify[]
|
OpenaiSession OpenaiSession[]
|
||||||
DifySession DifySession[]
|
OpenaiSetting OpenaiSetting?
|
||||||
DifySetting DifySetting?
|
Template Template[]
|
||||||
|
Dify Dify[]
|
||||||
|
DifySession DifySession[]
|
||||||
|
DifySetting DifySetting?
|
||||||
}
|
}
|
||||||
|
|
||||||
model Session {
|
model Session {
|
||||||
|
@ -388,13 +388,18 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (connection === 'close') {
|
if (connection === 'close') {
|
||||||
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
|
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
|
||||||
|
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
|
||||||
|
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
|
||||||
if (shouldReconnect) {
|
if (shouldReconnect) {
|
||||||
await this.connectToWhatsapp(this.phoneNumber);
|
await this.connectToWhatsapp(this.phoneNumber);
|
||||||
} else {
|
} else {
|
||||||
this.sendDataWebhook(Events.STATUS_INSTANCE, {
|
this.sendDataWebhook(Events.STATUS_INSTANCE, {
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
status: 'closed',
|
status: 'closed',
|
||||||
|
disconnectionAt: new Date(),
|
||||||
|
disconnectionReasonCode: statusCode,
|
||||||
|
disconnectionObject: JSON.stringify(lastDisconnect),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
||||||
@ -402,6 +407,9 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
where: { id: this.instanceId },
|
where: { id: this.instanceId },
|
||||||
data: {
|
data: {
|
||||||
connectionStatus: 'close',
|
connectionStatus: 'close',
|
||||||
|
disconnectionAt: new Date(),
|
||||||
|
disconnectionReasonCode: statusCode,
|
||||||
|
disconnectionObject: JSON.stringify(lastDisconnect),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user