evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

Erros homolog 09/09/2025

Open WanderleyGrecco opened this issue 1 year ago • 6 comments

Welcome!

  • [x] Yes, I have searched for similar issues on GitHub and found none.

What did you do?

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:23:30 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:23:30 INFO [ChannelStartupService] [string] Message duplicated ignored: 3F5BB0A0F7C5814F0D52

2025/09/09 10:24AM 50 pid=190 hostname=82dd79529a66 key={"remoteJid":"[email protected]","fromMe":false,"id":"3A62B02B158CBBC0B956","participant":"[email protected]","participantAlt":"54095264137225@lid"} err={"type":"TypeError","message":"The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object","stack":"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object\n at Function.from (node:buffer:322:9)\n at SenderKeyState.getSigningKeyPublic (file:///evolution/node_modules/baileys/lib/Signal/Group/sender-key-state.js:61:23)\n at GroupCipher.decrypt (file:///evolution/node_modules/baileys/lib/Signal/Group/group_cipher.js:38:57)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async executeTransactionWork (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:293:24)\n at async Object.transaction (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:439:28)\n at async decrypt (file:///evolution/node_modules/baileys/lib/Utils/decode-wa-message.js:194:45)\n at async file:///evolution/node_modules/baileys/lib/Socket/messages-recv.js:962:21\n at async file:///evolution/node_modules/baileys/lib/Utils/make-mutex.js:16:36\n at async Promise.all (index 0)","code":"ERR_INVALID_ARG_TYPE"} messageType=skmsg [email protected] [email protected] isSessionRecordError=false msg=failed to decrypt message

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:00 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:00 WARN [ChatwootService] [string] no body message found

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:24:00 LOG [ChannelStartupService] [string] Update not read messages [email protected]

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:24:00 LOG [ChannelStartupService] [object]

{

key: {

remoteJid: '[email protected]',

remoteJidAlt: undefined,

fromMe: false,

id: '3A62B02B158CBBC0B956',

participant: '[email protected]',

participantAlt: '54095264137225@lid'

},

pushName: 'Vitor Gabriel',

status: 'DELIVERY_ACK',

 message: {

senderKeyDistributionMessage: {

  groupId: '[email protected]',

  axolotlSenderKeyDistributionMessage: [Array]

},

messageContextInfo: { deviceListMetadata: [Object], deviceListMetadataVersion: 2 }

},

contextInfo: undefined,

messageType: 'unknown',

messageTimestamp: 1757427840,

instanceId: 'bc2c65dc-a04b-483e-b668-0d4cabec619c',

source: 'ios'

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:01 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:24:01 INFO [ChannelStartupService] [string] Message duplicated ignored: 3A62B02B158CBBC0B956

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:05 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:05 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:05 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:650

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[n,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,i=e.includes("@g.us");i?o=e:o=+${e};let n;return i?n=await t.contacts.search({accountId:this.provider.accountId,q:o}):n=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!n&&n?.payload?.length===0?(this.logger.warn("contact not found"),null):i?n.payload.find(r=>r.identifier===o):n.payload.length>1?this.findContactInContactList(n.payload,o):n.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let i=t.reduce((r,a)=>a.length>r.length?a:r,""),n=s.find(r=>r.phone_number===i);if(n)return n;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((i,n)=>{t.forEach((r,a)=>{let c=o.length-1===n&&t.length-1===a?null:"OR";e.push({attribute_key:i,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,i=${s.instanceName}:createConversation-${o},n=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(i)){let a=await this.cache.get(i);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(n)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(n);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(i)){let c=await this.cache.get(i);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(n,!0,30),this.logger.verbose(Bloqueio adquirido para: ${n});try{if(await this.cache.has(i))return await this.cache.get(i);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let S=y.payload.find(E=>E.inbox_id==d.id);if(S&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(S)}),S&&this.provider.conversationPending&&S.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:S.id,data:{status:"pending"}})):(S=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(S)})),S))return this.logger.verbose(Returning existing conversation ID: ${S.id}),this.cache.set(i,S.id),S.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(i))return await this.cache.get(i);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(i,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(n),this.logger.verbose(Block released for: ${n})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let i=o.payload.find(n=>n.name===this.getClientCwConfig().nameInbox);return i?(this.cache.set(e,i),i):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,i,n,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:n,private:i||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(n=>n.inbox_id===e.id&&n.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let i=await this.clientCw(s);if(!i)return this.logger.warn("client not found"),null;let n=await this.findContact(s,"123456");if(!n)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,n);if(!a){this.logger.warn("conversation not found");return}let c=await i.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,i,n,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new hn.default;i&&l.append("content",i),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&n){let h=await this.getReplyToIds(r,n);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,i){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new hn.default;e&&l.append("content",e),l.append("message_type",t),o&&i&&l.append("attachments[]",o,{filename:i});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,i){try{let n=yn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(n?.ext)||"",a=n?.name+n?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:i?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&n&&[".gif",".svg",".tiff",".tif"].includes(n?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:i?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(n){this.logger.error(n)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),i=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,n=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=i.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(n==null)c=i;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${n}:]:[];d.push(i),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){i||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");fn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:614)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:05 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:650

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[n,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,i=e.includes("@g.us");i?o=e:o=+${e};let n;return i?n=await t.contacts.search({accountId:this.provider.accountId,q:o}):n=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!n&&n?.payload?.length===0?(this.logger.warn("contact not found"),null):i?n.payload.find(r=>r.identifier===o):n.payload.length>1?this.findContactInContactList(n.payload,o):n.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let i=t.reduce((r,a)=>a.length>r.length?a:r,""),n=s.find(r=>r.phone_number===i);if(n)return n;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((i,n)=>{t.forEach((r,a)=>{let c=o.length-1===n&&t.length-1===a?null:"OR";e.push({attribute_key:i,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,i=${s.instanceName}:createConversation-${o},n=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(i)){let a=await this.cache.get(i);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(n)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(n);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(i)){let c=await this.cache.get(i);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(n,!0,30),this.logger.verbose(Bloqueio adquirido para: ${n});try{if(await this.cache.has(i))return await this.cache.get(i);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let S=y.payload.find(E=>E.inbox_id==d.id);if(S&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(S)}),S&&this.provider.conversationPending&&S.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:S.id,data:{status:"pending"}})):(S=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(S)})),S))return this.logger.verbose(Returning existing conversation ID: ${S.id}),this.cache.set(i,S.id),S.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(i))return await this.cache.get(i);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(i,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(n),this.logger.verbose(Block released for: ${n})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let i=o.payload.find(n=>n.name===this.getClientCwConfig().nameInbox);return i?(this.cache.set(e,i),i):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,i,n,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:n,private:i||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(n=>n.inbox_id===e.id&&n.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let i=await this.clientCw(s);if(!i)return this.logger.warn("client not found"),null;let n=await this.findContact(s,"123456");if(!n)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,n);if(!a){this.logger.warn("conversation not found");return}let c=await i.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,i,n,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new hn.default;i&&l.append("content",i),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&n){let h=await this.getReplyToIds(r,n);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,i){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new hn.default;e&&l.append("content",e),l.append("message_type",t),o&&i&&l.append("attachments[]",o,{filename:i});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,i){try{let n=yn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(n?.ext)||"",a=n?.name+n?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:i?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&n&&[".gif",".svg",".tiff",".tif"].includes(n?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:i?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(n){this.logger.error(n)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),i=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,n=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=i.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(n==null)c=i;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${n}:]:[];d.push(i),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){i||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");fn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:614)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:06 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

Message received from phone, id= 3EB06D42EC95FEB1239B25 WebMessageInfo {

messageStubParameters: [],

labels: [],

userReceipt: [],

reactions: [],

pollUpdates: [],

eventResponses: [],

statusMentions: [],

messageAddOns: [],

statusMentionSources: [],

supportAiCitations: [],

key: MessageKey {

remoteJid: '[email protected]',

fromMe: false,

id: '3AE3B13EA46248765B7B'

},

message: Message {

conversation: 'Nesse meu caso foi uma migração da gupshup para app próprio'

},

messageTimestamp: Long { low: 1757427768, high: 0, unsigned: true },

participant: '[email protected]',

messageSecret: Uint8Array(32) [

244, 149,  25,  52, 181, 228, 115, 106,

 67,  92,   2, 133, 165, 236,  14, 156,

 84,  62, 221, 246, 255,  51, 129, 153,

 12, 183, 214,  65, 234,   3, 155, 224

],

reportingTokenInfo: ReportingTokenInfo {

reportingTag: Uint8Array(20) [

    1,  10,  83, 159,   2,  54,

  207,  64, 200,  16, 163, 217,

  149,  79, 147, 182, 111, 250,

  243, 138

]

},

isMentionedInStatus: false

}

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:24:06 INFO [ChannelStartupService] [string] Message duplicated ignored: 3AE3B13EA46248765B7B

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:06 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

Message received from phone, id= 3EB02017DBD13BA8C1F610 WebMessageInfo {

messageStubParameters: [],

labels: [],

userReceipt: [],

reactions: [],

pollUpdates: [],

eventResponses: [],

statusMentions: [],

messageAddOns: [],

statusMentionSources: [],

supportAiCitations: [],

key: MessageKey {

remoteJid: '[email protected]',

fromMe: false,

id: '3F5BB0A0F7C5814F0D52'

},

message: Message {

extendedTextMessage: ExtendedTextMessage {

  text: 'As vezes só aparece que esta em aprovação mas ta funcionando',

  previewType: 0,

  contextInfo: [ContextInfo],

  inviteLinkGroupTypeV2: 0

}

},

messageTimestamp: Long { low: 1757427809, high: 0, unsigned: true },

participant: '[email protected]',

reportingTokenInfo: ReportingTokenInfo {

reportingTag: Uint8Array(16) [

    1, 10, 168, 156, 119,  16,

  240,  7, 178, 132,  91, 225,

  162, 14,  72,  48

]

},

isMentionedInStatus: false

}

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 11:24:06 INFO [ChannelStartupService] [string] Message duplicated ignored: 3F5BB0A0F7C5814F0D52

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:16 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 11:24:16 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:650

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[n,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,i=e.includes("@g.us");i?o=e:o=+${e};let n;return i?n=await t.contacts.search({accountId:this.provider.accountId,q:o}):n=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!n&&n?.payload?.length===0?(this.logger.warn("contact not found"),null):i?n.payload.find(r=>r.identifier===o):n.payload.length>1?this.findContactInContactList(n.payload,o):n.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let i=t.reduce((r,a)=>a.length>r.length?a:r,""),n=s.find(r=>r.phone_number===i);if(n)return n;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((i,n)=>{t.forEach((r,a)=>{let c=o.length-1===n&&t.length-1===a?null:"OR";e.push({attribute_key:i,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,i=${s.instanceName}:createConversation-${o},n=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(i)){let a=await this.cache.get(i);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(n)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(n);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(i)){let c=await this.cache.get(i);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(n,!0,30),this.logger.verbose(Bloqueio adquirido para: ${n});try{if(await this.cache.has(i))return await this.cache.get(i);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let S=y.payload.find(E=>E.inbox_id==d.id);if(S&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(S)}),S&&this.provider.conversationPending&&S.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:S.id,data:{status:"pending"}})):(S=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(S)})),S))return this.logger.verbose(Returning existing conversation ID: ${S.id}),this.cache.set(i,S.id),S.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(i))return await this.cache.get(i);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(i,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(n),this.logger.verbose(Block released for: ${n})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let i=o.payload.find(n=>n.name===this.getClientCwConfig().nameInbox);return i?(this.cache.set(e,i),i):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,i,n,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:n,private:i||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(n=>n.inbox_id===e.id&&n.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let i=await this.clientCw(s);if(!i)return this.logger.warn("client not found"),null;let n=await this.findContact(s,"123456");if(!n)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,n);if(!a){this.logger.warn("conversation not found");return}let c=await i.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,i,n,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new hn.default;i&&l.append("content",i),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&n){let h=await this.getReplyToIds(r,n);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,i){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new hn.default;e&&l.append("content",e),l.append("message_type",t),o&&i&&l.append("attachments[]",o,{filename:i});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,i){try{let n=yn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(n?.ext)||"",a=n?.name+n?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:i?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&n&&[".gif",".svg",".tiff",".tif"].includes(n?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:i?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(n){this.logger.error(n)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),i=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,n=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=i.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(n==null)c=i;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${n}:]:[];d.push(i),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){i||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");fn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:614)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

What did you expect?

Que não ouve erros.

What did you observe instead of what you expected?

erros.

Screenshots/Videos

No response

Which version of the API are you using?

2.3.3 homolog 09/09/2025

What is your environment?

Docker

Other environment specifications

No response

If applicable, paste the log output

No response

Additional Notes

No response

WanderleyGrecco avatar Sep 09 '25 14:09 WanderleyGrecco

Subimos um novo commit hoje

DavidsonGomes avatar Sep 09 '25 15:09 DavidsonGomes

Com a versão de hoje, estou tendo o problema ainda:

Deploying migrations for postgresql

Database URL:

[email protected] db:deploy

node runWithProvider.js "rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma"

Environment variables loaded from .env

Prisma schema loaded from prisma/postgresql-schema.prisma

Datasource "db": PostgreSQL database "evolution", schema "public" at "postgresevo:5432"

PostgreSQL database evolution created at postgresevo:5432

55 migrations found in prisma/migrations

Applying migration 20240609181238_init

Applying migration 20240610144159_create_column_profile_name_instance

Applying migration 20240611125754_create_columns_whitelabel_chatwoot

Applying migration 20240611202817_create_columns_debounce_time_typebot

Applying migration 20240712144948_add_business_id_column_to_instances

Applying migration 20240712150256_create_templates_table

Applying migration 20240712155950_adjusts_in_templates_table

Applying migration 20240712162206_remove_templates_table

Applying migration 20240712223655_column_fallback_typebot

Applying migration 20240712230631_column_ignore_jids_typebot

Applying migration 20240713184337_add_media_table

Applying migration 20240718121437_add_openai_tables

Applying migration 20240718123923_adjusts_openai_tables

Applying migration 20240722173259_add_name_column_to_openai_creds

Applying migration 20240722173518_add_name_column_to_openai_creds

Applying migration 20240723152648_adjusts_in_column_openai_creds

Applying migration 20240723200254_add_webhookurl_on_message

Applying migration 20240725184147_create_template_table

Applying migration 20240725202651_add_webhook_url_template_table

Applying migration 20240725221646_modify_token_instance_table

Applying migration 20240729115127_modify_trigger_type_openai_typebot_table

Applying migration 20240729180347_modify_typebot_session_status_openai_typebot_table

Applying migration 20240730152156_create_dify_tables

Applying migration 20240801193907_add_column_speech_to_text_openai_setting_table

Applying migration 20240803163908_add_column_description_on_integrations_table

Applying migration 20240808210239_add_column_function_url_openaibot_table

Applying migration 20240811021156_add_chat_name_column

Applying migration 20240811183328_add_unique_index_for_remoted_jid_and_instance_in_contacts

Applying migration 20240813003116_make_label_unique_for_instance

Applying migration 20240814173033_add_ignore_jids_chatwoot

Applying migration 20240814202359_integrations_unification

Applying migration 20240817110155_add_trigger_type_advanced

Applying migration 20240819154941_add_context_to_integration_session

Applying migration 20240821120816_bot_id_integration_session

Applying migration 20240821171327_add_generic_bot_table

Applying migration 20240821194524_add_flowise_table

Applying migration 20240824161333_add_type_on_integration_sessions

Applying migration 20240825130616_change_to_evolution_bot

Applying migration 20240828140837_add_is_on_whatsapp_table

Applying migration 20240828141556_remove_name_column_from_on_whatsapp_table

Applying migration 20240830193533_changed_table_case

Applying migration 20240906202019_add_headers_on_webhook_config

Applying migration 20241001180457_add_message_status

Applying migration 20241006130306_alter_status_on_message_table

Applying migration 20241007164026_add_unread_messages_on_chat_table

Applying migration 20241011085129_create_pusher_table

Applying migration 20241011100803_split_messages_and_time_per_char_integrations

Applying migration 20241017144950_create_index

Applying migration 20250116001415_add_wavoip_token_to_settings_table

Applying migration 20250225180031_add_nats_integration

Applying migration 20250514232744_add_n8n_table

Applying migration 20250515211815_add_evoai_table

Applying migration 20250516012152_remove_unique_atribute_for_file_name_in_media

Applying migration 20250612155048_add_coluns_trypebot_tables

Applying migration 20250613143000_add_lid_column_to_is_onwhatsapp

The following migration(s) have been applied:

migrations/

└─ 20240609181238_init/

└─ migration.sql

└─ 20240610144159_create_column_profile_name_instance/

└─ migration.sql

└─ 20240611125754_create_columns_whitelabel_chatwoot/

└─ migration.sql

└─ 20240611202817_create_columns_debounce_time_typebot/

└─ migration.sql

└─ 20240712144948_add_business_id_column_to_instances/

└─ migration.sql

└─ 20240712150256_create_templates_table/

└─ migration.sql

└─ 20240712155950_adjusts_in_templates_table/

└─ migration.sql

└─ 20240712162206_remove_templates_table/

└─ migration.sql

└─ 20240712223655_column_fallback_typebot/

└─ migration.sql

└─ 20240712230631_column_ignore_jids_typebot/

└─ migration.sql

└─ 20240713184337_add_media_table/

└─ migration.sql

└─ 20240718121437_add_openai_tables/

└─ migration.sql

└─ 20240718123923_adjusts_openai_tables/

└─ migration.sql

└─ 20240722173259_add_name_column_to_openai_creds/

└─ migration.sql

└─ 20240722173518_add_name_column_to_openai_creds/

└─ migration.sql

└─ 20240723152648_adjusts_in_column_openai_creds/

└─ migration.sql

└─ 20240723200254_add_webhookurl_on_message/

└─ migration.sql

└─ 20240725184147_create_template_table/

└─ migration.sql

└─ 20240725202651_add_webhook_url_template_table/

└─ migration.sql

└─ 20240725221646_modify_token_instance_table/

└─ migration.sql

└─ 20240729115127_modify_trigger_type_openai_typebot_table/

└─ migration.sql

└─ 20240729180347_modify_typebot_session_status_openai_typebot_table/

└─ migration.sql

└─ 20240730152156_create_dify_tables/

└─ migration.sql

└─ 20240801193907_add_column_speech_to_text_openai_setting_table/

└─ migration.sql

└─ 20240803163908_add_column_description_on_integrations_table/

└─ migration.sql

└─ 20240808210239_add_column_function_url_openaibot_table/

└─ migration.sql

└─ 20240811021156_add_chat_name_column/

└─ migration.sql

└─ 20240811183328_add_unique_index_for_remoted_jid_and_instance_in_contacts/

└─ migration.sql

└─ 20240813003116_make_label_unique_for_instance/

└─ migration.sql

└─ 20240814173033_add_ignore_jids_chatwoot/

└─ migration.sql

└─ 20240814202359_integrations_unification/

└─ migration.sql

└─ 20240817110155_add_trigger_type_advanced/

└─ migration.sql

└─ 20240819154941_add_context_to_integration_session/

└─ migration.sql

└─ 20240821120816_bot_id_integration_session/

└─ migration.sql

└─ 20240821171327_add_generic_bot_table/

└─ migration.sql

└─ 20240821194524_add_flowise_table/

└─ migration.sql

└─ 20240824161333_add_type_on_integration_sessions/

└─ migration.sql

└─ 20240825130616_change_to_evolution_bot/

└─ migration.sql

└─ 20240828140837_add_is_on_whatsapp_table/

└─ migration.sql

└─ 20240828141556_remove_name_column_from_on_whatsapp_table/

└─ migration.sql

└─ 20240830193533_changed_table_case/

└─ migration.sql

└─ 20240906202019_add_headers_on_webhook_config/

└─ migration.sql

└─ 20241001180457_add_message_status/

└─ migration.sql

└─ 20241006130306_alter_status_on_message_table/

└─ migration.sql

└─ 20241007164026_add_unread_messages_on_chat_table/

└─ migration.sql

└─ 20241011085129_create_pusher_table/

└─ migration.sql

└─ 20241011100803_split_messages_and_time_per_char_integrations/

└─ migration.sql

└─ 20241017144950_create_index/

└─ migration.sql

└─ 20250116001415_add_wavoip_token_to_settings_table/

└─ migration.sql

└─ 20250225180031_add_nats_integration/

└─ migration.sql

└─ 20250514232744_add_n8n_table/

└─ migration.sql

└─ 20250515211815_add_evoai_table/

└─ migration.sql

└─ 20250516012152_remove_unique_atribute_for_file_name_in_media/

└─ migration.sql

└─ 20250612155048_add_coluns_trypebot_tables/

└─ migration.sql

└─ 20250613143000_add_lid_column_to_is_onwhatsapp/

└─ migration.sql

All migrations have been successfully applied.

npm notice

npm notice New major version of npm available! 10.8.2 -> 11.6.0

npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.0

npm notice To update run: npm install -g [email protected]

npm notice

Migration succeeded

[email protected] db:generate

node runWithProvider.js "npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma"

Environment variables loaded from .env

Prisma schema loaded from prisma/postgresql-schema.prisma

┌─────────────────────────────────────────────────────────┐

│ Update available 6.11.1 -> 6.15.0 │

│ Run the following to update │

│ npm i --save-dev prisma@latest │

│ npm i @prisma/client@latest │

└─────────────────────────────────────────────────────────┘

✔ Generated Prisma Client (v6.11.1) to ./node_modules/@prisma/client in 402ms

Start by importing your Prisma Client (See: https://pris.ly/d/importing-client)

Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate

Prisma generate succeeded

[email protected] start:prod

node dist/main

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:37 VERBOSE [CacheEngine] [string] RedisCache initialized for groups

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:37 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheEngine] [string] RedisCache initialized for instance

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheEngine] [string] RedisCache initialized for baileys

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 INFO [WA MODULE] [string] Module - ON

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [Redis] [string] redis connecting

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 VERBOSE [Redis] [string] redis ready

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 INFO [PrismaRepository] [string] Repository:Prisma - ON

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:46:38 LOG [SERVER] [string] HTTP - ON: 8080

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] Auto create chatwoot instance

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] Creating chatwoot inbox

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] Inbox created - inboxId: 1

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] Creating chatwoot bot contact

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] Contact created - contactId: 1

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:14 LOG [ChatwootService] [string] QR code enabled

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 LOG [ChatwootService] [string] Init message sent

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:15 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:15 INFO [ChannelStartupService] [string] Browser: WhatsAPI,chrome,5.15.0-151-generic

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:15 INFO [ChannelStartupService] [string] Baileys version: 2.3000.1026886407

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:15 INFO [ChannelStartupService] [string] Group Ignore: false

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:16 LOG [ChannelStartupService] [string]

{ instance: wanderley pairingCode: null, qrcodeCount: 1 }

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄

█ ▄▄▄▄▄ █▀▀███ █ ▄▀▄ ██▄▄ ▄▀▄ ▄▀█ ▄▄▄▄ █▀ ▀ █▄ ██ ▄▄▄▄▄ █

█ █ █ █▄▄▀▀ ▀███▀▄▀█▄██████▄█ ▄▄█ ▄▄█ ██▄▄ ▄▀▄ ██ █ █ █

█ █▄▄▄█ █ ██ ▀▀██▀█▀█▄█▀▄ ▄▄▄ ▀▄ █▄██ ▄▄▄ ▀▄██ █▄▄▄█ █

█▄▄▄▄▄▄▄█ ▀ ▀▄█ ▀ █▄▀ ▀▄▀▄█ █▄█ ▀▄█▄█ █ ▀ █▄▀ ▀▄█ █▄▄▄▄▄▄▄█

█▄▄█ ▀█▄ ▀█▀█▀ ▀▄█▄ █▄ ▄▄▄ ▄ ▄▄██ ▄ ▄██▄▄▄▄▄▀█▄▄▄▀▄ ▄▀▄▄▀█

███▀▀██▄█▀▄ ▄ ▀█ ▄▀▄▄▄ ▀█▄ ▄ ▄▄▀▀█ █▀ ▀▄█▄ ██ ▀▀███▀█ █

██▄█▄▀█▄ ▀▄█ █▄█ ▀█▄ █ ▀▀██▀█▄█▀▄▄▄▀▄ ▄█▄▄▄ ▄▄ ▄▄▄█ █▄ █

█▄▄ █▀▀▄ ▀▄▄ █▄▀█▄▄█▄▄▄▄▄█▀▄▄▄█ ▄▀▀▀ ▀█▄▄▀ ▄▄▀▄█▀██▀▀█

█ █ ▀▀▄▄▄██▀▄█▀ ▄▄ ▄▄▀▄▀▀▄ ▀ ▀▄█▄ ▄▄▄▄ ▀▀██ █▄ ▄▀ ▀▀█▄▄▄█

█▄ ▄▀█▀▄▄▀ █ ▀▄▀▄▄▀▀█ ▄▄▄▄▄ █▄▄██ ██▀██▀█ ▀██▄██▀▀▄██▀▄█

█▀█▀▄█▀▄▄█▄ █▄███ █▄ ██ ▄ ▄ ▄▄▄▄▄▀██ ▄▄▄▄▄▄█ ▀█▄▀█▄█▀ ▄██ █

██▀ ▄ ▄▄█▀ ██ █▀█ █▄▀ █▄▀▀▄█▀▀▄█▀ ▄▀▀ ▀▄█ ▀█▀▄▀ ▄█ ▄ ▀▄▄ █

█▀▀▀█▀▄▄▀██▄█▄ ▄▀ ▄██ ▄▄▀ ▄ ▀█▄▀██▀ █▄▀▄██▄▄▄ ██ ▄▀ ▀█▄▀█

██▄█ ▄▄▄ ▄▄▀▄▀███▀▀▄▀█▄▀▀ ▄▄▄ ▄▄▀ ▄██ ▄ ▄▄▄ ▄▄▄██

█▀▄▄ █▄█ ▄█▀▀▄▀██▄█▀▀██▀▄▄ █▄█ ▀▄██▀ █▀▀█ ▄▀ ██▄ █▄█ ▄█▀ █

███ ▀ ▄▄▄█▄▄ ▀▀███ ▄█▄███▄ █▀▄▄█▀▄ █ ▄▄ ▀▀▀ ▄ ▄▄ ▄█

█ ▀██▀▀▄▀▄ ▀█ █▄▀ ▄▄ ▀█▀▄▄█▄▄ ▀ ▄█ █▄▄ █▄▄▀▄█ ▄▄ █▄▄▀███

█▄█ ▄ ▄█ █▄ ▀▄▄███ ▀ █▀██▀▀ ▀▄█▄▀▄▀▀▀▀▀▄ ▄▄ ▀ █▀ ▀▄▀█▀ █

█▄ ▀ ▄█▄▀▄▀▄█▀▄▀ █ ▀ ▄▄ ▄█▄ ▀ ▄ ▄ █ ▀█ ▄▄█▀ █ ▀█▀▀ ▀▄▀█▀█

██▀█▄▄ ▄▄█▄█▄ █▄ ▄▄▀█ ▀▄ ▄ ▄ ██▀▄ ▄█▀ ▀▄▄ ██ ▄▀▄▀▄▄ ▄█

███▀ ▄█▄▀█▀ ▄██ █▄ ▀▀ █▀█ ▄██▀█▄ █ ▄█▀▄█ ▄█▄█▄█▄█▀█▄ █ ▄█

█ ▀ █ ▄▄███▀▀ █▄▄ ██▄▀ ▀▀ ▀ ▄ ▄ ▄▄▄███▀▀ ▄█ █▀▄█ ▄█

█▄▀▄▀ ▄██▄ ▀▄ ██▄▄▄▄ █▄█ ▄ █▄▀ ▀█▄█ ▄█▀▄██▄▀▄▄ █▀ ▄▄█▄▀██

█ ▀ ▀▀▄▄▄██▀█▄▄▀ █ ▀ ▄▄▀▀█▄▄▀▄▄▄ █▀▄▀ ▀▀▀▄▀▀ █▀█▀▄ ▀ ▄█ █

███████▄▄▀ ██▄▄ █ ▄▀█ ▄██▀ ▄▄▄ █ ██▄▄█ █ ▀ ▄▄▄ ▀▀▄ █

█ ▄▄▄▄▄ █▄▄▀▄█▄ █▄▄ ▄ ▀ █▄█ ██▄▀ ▄█ ▀█▄█▀ █▄█ ▄█ ██

█ █ █ █▀█▄█▀▄▄█▀ ▀ ▄▀▀ ▀ ▄ ▀▄▄██▄▀ █▀█▀ ▄▄▄▄▄▄▄ █ █

█ █▄▄▄█ █▀▀▀▀█ ▄██ ▄▄▄ █▀█ ▄▄█▀█▄▄▄▄█▀█▀▀▄▀▄ ▀▀▄ ▀▄█ ███▄█

█▄▄▄▄▄▄▄█▄▄█▄▄█▄▄██▄██▄▄██▄█▄█▄▄▄▄███▄▄▄▄▄▄█▄████▄██▄▄▄▄▄██

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:16 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:16 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:17 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:17 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:17 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:17 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

2025/09/09 01:48PM 50 pid=189 hostname=8f75d9df37d9 node={"tag":"stream:error","attrs":{"code":"515"}} msg=stream errored out

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:54 INFO [ChannelStartupService] [string] Browser: WhatsAPI,chrome,5.15.0-151-generic

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:54 INFO [ChannelStartupService] [string] Baileys version: 2.3000.1026886407

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:54 INFO [ChannelStartupService] [string] Group Ignore: false

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:56 INFO [ChannelStartupService] [string]

┌──────────────────────────────┐

│ CONNECTED TO WHATSAPP │

└──────────────────────────────┘

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:48:56 INFO [ChannelStartupService] [string]

    wuid: 556584012654                  

    name: wanderley

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:56 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:56 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:56 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:56 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:57 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:48:57 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

recv 500 chats, 500 contacts, 681 msgs (is latest: true, progress: 0%), type: 0

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:02 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 189 - Tue Sep 09 2025 14:49:02 LOG [ChannelStartupService] [string] Update messages [

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "3A3A1E84677FD47B2D79",

  "fromMe": false

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "A6EEC06A5AAA5DC9287C5BB6B9A7FE2F",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "F20FF4FFCFFAA0021EF741CB3CB37F96",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "C337407192EE5B506562E7CF35CAE51A",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "4F77843C881A6DA89D74B1CB125AC549",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "C9F5C0236825302C72AFAAC697730F3B",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "A1D8067830B2E440DC9A9BFA2785300C",

  "fromMe": false

},

"update": {

  "starred": true

}

}

]

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:02 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:02 ERROR [unhandledRejection] [object]

{

origin: Promise {

<rejected> PrismaClientValidationError: 

Invalid `this.cache.delete()` invocation in

/evolution/dist/main.js:227:33195



  224 `),n.url&&(i+=`URL:${n.url}

  225 `),n.wuid||(n.wuid=J(n.phoneNumber)),i+=`item1.TEL;waid=${n.wuid}:${n.phoneNumber}

  226 item1.X-ABLabel:Celular

→ 227 END:VCARD`,i};return e.contact.length===1?t.contact={displayName:e.contact[0].fullName,vcard:o(e.contact[0])}:t.contactsArrayMessage={displayName:`${e.contact.length} contacts`,contacts:e.contact.map(n=>({displayName:n.fullName,vcard:o(n)}))},await this.sendMessageWithTyping(e.number,{contacts:e.contact.map(n=>({name:{formatted_name:n.fullName,first_name:n.fullName},phones:[{phone:n.phoneNumber}],urls:[{url:n.url}],emails:[{email:n.email}],org:{company:n.organization}})),message:t},{delay:e?.delay,presence:"composing",quoted:e?.quoted,linkPreview:e?.linkPreview,mentionsEveryOne:e?.mentionsEveryOne,mentioned:e?.mentioned})}async reactionMessage(e){return await this.sendMessageWithTyping(e.key.remoteJid,{reactionMessage:{key:e.key,text:e.reaction}})}async getBase64FromMediaMessage(e){try{let t=e.message,o=t.messageType.includes("Message")?t.messageType:t.messageType+"Message",n=t.message[o];return{mediaType:t.messageType,fileName:n?.fileName,caption:n?.caption,size:{fileLength:n?.fileLength,height:n?.fileLength,width:n?.width},mimetype:n?.mime_type,base64:t.message.base64}}catch(t){throw this.logger.error(t),new f(t.toString())}}async deleteMessage(){throw new f("Method not available on WhatsApp Business API")}async mediaSticker(){throw new f("Method not available on WhatsApp Business API")}async pollMessage(){throw new f("Method not available on WhatsApp Business API")}async statusMessage(){throw new f("Method not available on WhatsApp Business API")}async reloadConnection(){throw new f("Method not available on WhatsApp Business API")}async whatsappNumber(){throw new f("Method not available on WhatsApp Business API")}async markMessageAsRead(){throw new f("Method not available on WhatsApp Business API")}async archiveChat(){throw new f("Method not available on WhatsApp Business API")}async markChatUnread(){throw new f("Method not available on WhatsApp Business API")}async fetchProfile(){throw new f("Method not available on WhatsApp Business API")}async offerCall(){throw new f("Method not available on WhatsApp Business API")}async sendPresence(){throw new f("Method not available on WhatsApp Business API")}async setPresence(){throw new f("Method not available on WhatsApp Business API")}async fetchPrivacySettings(){throw new f("Method not available on WhatsApp Business API")}async updatePrivacySettings(){throw new f("Method not available on WhatsApp Business API")}async fetchBusinessProfile(){throw new f("Method not available on WhatsApp Business API")}async updateProfileName(){throw new f("Method not available on WhatsApp Business API")}async updateProfileStatus(){throw new f("Method not available on WhatsApp Business API")}async updateProfilePicture(){throw new f("Method not available on WhatsApp Business API")}async removeProfilePicture(){throw new f("Method not available on WhatsApp Business API")}async blockUser(){throw new f("Method not available on WhatsApp Business API")}async updateMessage(){throw new f("Method not available on WhatsApp Business API")}async createGroup(){throw new f("Method not available on WhatsApp Business API")}async updateGroupPicture(){throw new f("Method not available on WhatsApp Business API")}async updateGroupSubject(){throw new f("Method not available on WhatsApp Business API")}async updateGroupDescription(){throw new f("Method not available on WhatsApp Business API")}async findGroup(){throw new f("Method not available on WhatsApp Business API")}async fetchAllGroups(){throw new f("Method not available on WhatsApp Business API")}async inviteCode(){throw new f("Method not available on WhatsApp Business API")}async inviteInfo(){throw new f("Method not available on WhatsApp Business API")}async sendInvite(){throw new f("Method not available on WhatsApp Business API")}async acceptInviteCode(){throw new f("Method not available on WhatsApp Business API")}async revokeInviteCode(){throw new f("Method not available on WhatsApp Business API")}async findParticipants(){throw new f("Method not available on WhatsApp Business API")}async updateGParticipant(){throw new f("Method not available on WhatsApp Business API")}async updateGSetting(){throw new f("Method not available on WhatsApp Business API")}async toggleEphemeral(){throw new f("Method not available on WhatsApp Business API")}async leaveGroup(){throw new f("Method not available on WhatsApp Business API")}async fetchLabels(){throw new f("Method not available on WhatsApp Business API")}async handleLabel(){throw new f("Method not available on WhatsApp Business API")}async receiveMobileCode(){throw new f("Method not available on WhatsApp Business API")}async fakeCall(){throw new f("Method not available on WhatsApp Business API")}};var Je=class{constructor(s,e,t,o,n){this.jid=s;this.exists=e;this.number=t;this.name=o;this.lid=n}},Is=class{},Cs=class{},Ye=class{};var vs=class{},As=class{},St=class{};var Ms=class{};var Rs=class{},Ns=class{},Ds=class{},Ps=class{};var bn=class{},_s=class extends bn{},Os=class extends _s{},xs=class extends _s{},ks=class{};var En=require("baileys"),Oe=class{constructor(s){this.cache=s;this.logger=new M("CacheService");s?this.logger.verbose(`cacheservice created using cache engine: ${s.constructor?.name}`):this.logger.verbose("cacheservice disabled")}async get(s){if(this.cache)return this.cache.get(s)}async hGet(s,e){if(!this.cache)return null;try{let t=await this.cache.hGet(s,e);return t?JSON.parse(t,En.BufferJSON.reviver):null}catch(t){return this.logger.error(t),null}}async set(s,e,t){this.cache&&this.cache.set(s,e,t)}async hSet(s,e,t){if(this.cache)try{let o=JSON.stringify(t,En.BufferJSON.replacer);await this.cache.hSet(s,e,o)}catch(o){this.logger.error(o)}}async has(s){if(this.cache)return this.cache.has(s)}async delete(s){if(this.cache)return this.cache.delete({

        data: {

          keyId: "3A3A1E84677FD47B2D79",

          remoteJid: "[email protected]",

          fromMe: false,

          participant: "[email protected]",

          status: "DELETED",

          pollUpdates: undefined,

          instanceId: "dd72a324-232d-4d13-9c7b-ecd2078ca4f4",

      +   Message: {

      +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,

      +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,

      +     connect: MessageWhereUniqueInput

      +   }

        }

 })

Argument `Message` is missing.

    at kn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)

    at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7102)

    at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

    at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

    at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

    at async messages.update (/evolution/dist/main.js:227:33153) {

  clientVersion: '6.11.1'

}

},

stderr: 2

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:02 ERROR [unhandledRejection] [object]

PrismaClientValidationError:

Invalid this.cache.delete() invocation in

/evolution/dist/main.js:227:33195

224 ),n.url&&(i+=URL:${n.url}

225 ),n.wuid||(n.wuid=J(n.phoneNumber)),i+=item1.TEL;waid=${n.wuid}:${n.phoneNumber}

226 item1.X-ABLabel:Celular

→ 227 END:VCARD,i};return e.contact.length===1?t.contact={displayName:e.contact[0].fullName,vcard:o(e.contact[0])}:t.contactsArrayMessage={displayName:${e.contact.length} contacts,contacts:e.contact.map(n=>({displayName:n.fullName,vcard:o(n)}))},await this.sendMessageWithTyping(e.number,{contacts:e.contact.map(n=>({name:{formatted_name:n.fullName,first_name:n.fullName},phones:[{phone:n.phoneNumber}],urls:[{url:n.url}],emails:[{email:n.email}],org:{company:n.organization}})),message:t},{delay:e?.delay,presence:"composing",quoted:e?.quoted,linkPreview:e?.linkPreview,mentionsEveryOne:e?.mentionsEveryOne,mentioned:e?.mentioned})}async reactionMessage(e){return await this.sendMessageWithTyping(e.key.remoteJid,{reactionMessage:{key:e.key,text:e.reaction}})}async getBase64FromMediaMessage(e){try{let t=e.message,o=t.messageType.includes("Message")?t.messageType:t.messageType+"Message",n=t.message[o];return{mediaType:t.messageType,fileName:n?.fileName,caption:n?.caption,size:{fileLength:n?.fileLength,height:n?.fileLength,width:n?.width},mimetype:n?.mime_type,base64:t.message.base64}}catch(t){throw this.logger.error(t),new f(t.toString())}}async deleteMessage(){throw new f("Method not available on WhatsApp Business API")}async mediaSticker(){throw new f("Method not available on WhatsApp Business API")}async pollMessage(){throw new f("Method not available on WhatsApp Business API")}async statusMessage(){throw new f("Method not available on WhatsApp Business API")}async reloadConnection(){throw new f("Method not available on WhatsApp Business API")}async whatsappNumber(){throw new f("Method not available on WhatsApp Business API")}async markMessageAsRead(){throw new f("Method not available on WhatsApp Business API")}async archiveChat(){throw new f("Method not available on WhatsApp Business API")}async markChatUnread(){throw new f("Method not available on WhatsApp Business API")}async fetchProfile(){throw new f("Method not available on WhatsApp Business API")}async offerCall(){throw new f("Method not available on WhatsApp Business API")}async sendPresence(){throw new f("Method not available on WhatsApp Business API")}async setPresence(){throw new f("Method not available on WhatsApp Business API")}async fetchPrivacySettings(){throw new f("Method not available on WhatsApp Business API")}async updatePrivacySettings(){throw new f("Method not available on WhatsApp Business API")}async fetchBusinessProfile(){throw new f("Method not available on WhatsApp Business API")}async updateProfileName(){throw new f("Method not available on WhatsApp Business API")}async updateProfileStatus(){throw new f("Method not available on WhatsApp Business API")}async updateProfilePicture(){throw new f("Method not available on WhatsApp Business API")}async removeProfilePicture(){throw new f("Method not available on WhatsApp Business API")}async blockUser(){throw new f("Method not available on WhatsApp Business API")}async updateMessage(){throw new f("Method not available on WhatsApp Business API")}async createGroup(){throw new f("Method not available on WhatsApp Business API")}async updateGroupPicture(){throw new f("Method not available on WhatsApp Business API")}async updateGroupSubject(){throw new f("Method not available on WhatsApp Business API")}async updateGroupDescription(){throw new f("Method not available on WhatsApp Business API")}async findGroup(){throw new f("Method not available on WhatsApp Business API")}async fetchAllGroups(){throw new f("Method not available on WhatsApp Business API")}async inviteCode(){throw new f("Method not available on WhatsApp Business API")}async inviteInfo(){throw new f("Method not available on WhatsApp Business API")}async sendInvite(){throw new f("Method not available on WhatsApp Business API")}async acceptInviteCode(){throw new f("Method not available on WhatsApp Business API")}async revokeInviteCode(){throw new f("Method not available on WhatsApp Business API")}async findParticipants(){throw new f("Method not available on WhatsApp Business API")}async updateGParticipant(){throw new f("Method not available on WhatsApp Business API")}async updateGSetting(){throw new f("Method not available on WhatsApp Business API")}async toggleEphemeral(){throw new f("Method not available on WhatsApp Business API")}async leaveGroup(){throw new f("Method not available on WhatsApp Business API")}async fetchLabels(){throw new f("Method not available on WhatsApp Business API")}async handleLabel(){throw new f("Method not available on WhatsApp Business API")}async receiveMobileCode(){throw new f("Method not available on WhatsApp Business API")}async fakeCall(){throw new f("Method not available on WhatsApp Business API")}};var Je=class{constructor(s,e,t,o,n){this.jid=s;this.exists=e;this.number=t;this.name=o;this.lid=n}},Is=class{},Cs=class{},Ye=class{};var vs=class{},As=class{},St=class{};var Ms=class{};var Rs=class{},Ns=class{},Ds=class{},Ps=class{};var bn=class{},_s=class extends bn{},Os=class extends _s{},xs=class extends _s{},ks=class{};var En=require("baileys"),Oe=class{constructor(s){this.cache=s;this.logger=new M("CacheService");s?this.logger.verbose(cacheservice created using cache engine: ${s.constructor?.name}`):this.logger.verbose("cacheservice disabled")}async get(s){if(this.cache)return this.cache.get(s)}async hGet(s,e){if(!this.cache)return null;try{let t=await this.cache.hGet(s,e);return t?JSON.parse(t,En.BufferJSON.reviver):null}catch(t){return this.logger.error(t),null}}async set(s,e,t){this.cache&&this.cache.set(s,e,t)}async hSet(s,e,t){if(this.cache)try{let o=JSON.stringify(t,En.BufferJSON.replacer);await this.cache.hSet(s,e,o)}catch(o){this.logger.error(o)}}async has(s){if(this.cache)return this.cache.has(s)}async delete(s){if(this.cache)return this.cache.delete({

    data: {

      keyId: "3A3A1E84677FD47B2D79",

      remoteJid: "[email protected]",

      fromMe: false,

      participant: "[email protected]",

      status: "DELETED",

      pollUpdates: undefined,

      instanceId: "dd72a324-232d-4d13-9c7b-ecd2078ca4f4",

  +   Message: {

  +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,

  +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,

  +     connect: MessageWhereUniqueInput

  +   }



}

  })

Argument Message is missing.

at kn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7102)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async messages.update (/evolution/dist/main.js:227:33153) {

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 189 - Tue Sep 09 2025 14:49:04 ERROR [ChatwootService] [object]

PrismaClientKnownRequestError:

Invalid this.prismaRepository.message.updateMany() invocation in

/evolution/dist/main.js:86:677

83 VALUES ($1, 'Contact', $2, 'labels', NOW()),[i,e]),!0}catch{return!1}}async findContact(s,e){let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o,n=e.includes("@g.us");n?o=e:o=+${e};let i;return n?i=await t.contacts.search({accountId:this.provider.accountId,q:o}):i=await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/contacts/filter,body:{payload:this.getFilterPayload(o)}}),!i&&i?.payload?.length===0?(this.logger.warn("contact not found"),null):n?i.payload.find(r=>r.identifier===o):i.payload.length>1?this.findContactInContactList(i.payload,o):i.payload[0]}async mergeContacts(s,e){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s,mergee_contact_id:e}})}catch{return this.logger.error("Error merging contacts"),null}}async mergeBrazilianContacts(s){try{return await(0,Mt.request)(this.getClientCwConfig(),{method:"POST",url:/api/v1/accounts/${this.provider.accountId}/actions/contact_merge,body:{base_contact_id:s.find(t=>t.phone_number.length===14)?.id,mergee_contact_id:s.find(t=>t.phone_number.length===13)?.id}})}catch{return this.logger.error("Error merging contacts"),null}}findContactInContactList(s,e){let t=this.getNumbers(e),o=this.getSearchableFields();if(s.length===2&&this.getClientCwConfig().mergeBrazilContacts&&e.startsWith("+55")){let r=this.mergeBrazilianContacts(s);if(r)return r}let n=t.reduce((r,a)=>a.length>r.length?a:r,""),i=s.find(r=>r.phone_number===n);if(i)return i;for(let r of s)for(let a of o)if(r[a]&&t.includes(r[a]))return r;return null}getNumbers(s){let e=[];if(e.push(s),s.startsWith("+55")&&s.length===14){let t=s.slice(0,5)+s.slice(6);e.push(t)}else if(s.startsWith("+55")&&s.length===13){let t=s.slice(0,5)+"9"+s.slice(5);e.push(t)}return e}getSearchableFields(){return["phone_number"]}getFilterPayload(s){let e=[],t=this.getNumbers(s),o=this.getSearchableFields();return o.forEach((n,i)=>{t.forEach((r,a)=>{let c=o.length-1===i&&t.length-1===a?null:"OR";e.push({attribute_key:n,filter_operator:"equal_to",values:[r.replace("+","")],query_operator:c})})}),e}async createConversation(s,e){let t=e.key.previousRemoteJid?.includes("@lid")&&e.key.senderPn,o=e.key.remoteJid,n=${s.instanceName}:createConversation-${o},i=${s.instanceName}:lock:createConversation-${o},r=5e3;try{if(t&&e.key.senderPn!==e.key.previousRemoteJid){let a=await this.findContact(s,e.key.remoteJid.split("@")[0]);if(a&&a.identifier!==e.key.senderPn&&(this.logger.verbose(Identifier needs update: (contact.identifier: ${a.identifier}, body.key.remoteJid: ${e.key.remoteJid}, body.key.senderPn: ${e.key.senderPn}),await this.updateContact(s,a.id,{identifier:e.key.senderPn,phone_number:+${e.key.senderPn.split("@")[0]}})===null)){let l=await this.findContact(s,e.key.senderPn.split("@")[0]);l&&(await this.mergeContacts(l.id,a.id),this.logger.verbose(Merge contacts: (${l.id}) ${l.phone_number} and (${a.id}) ${a.phone_number}))}}if(this.logger.verbose("--- Start createConversation ---"),this.logger.verbose(Instance: ${JSON.stringify(s)}),await this.cache.has(n)){let a=await this.cache.get(n);return this.logger.verbose(Found conversation to: ${o}, conversation ID: ${a}),a}if(await this.cache.has(i)){this.logger.verbose(Opera\xE7\xE3o de cria\xE7\xE3o j\xE1 em andamento para ${o}, aguardando resultado...);let a=Date.now();for(;await this.cache.has(i);){if(Date.now()-a>r){this.logger.warn(Timeout aguardando lock para ${o});break}if(await new Promise(c=>setTimeout(c,300)),await this.cache.has(n)){let c=await this.cache.get(n);return this.logger.verbose(Resolves creation of: ${o}, conversation ID: ${c}),c}}}await this.cache.set(i,!0,30),this.logger.verbose(Bloqueio adquirido para: ${i});try{if(await this.cache.has(n))return await this.cache.get(n);let a=await this.clientCw(s);if(!a)return null;let c=o.includes("@g.us"),l=c?o:o.split("@")[0],u=e.key.fromMe?l:e.pushName,d=await this.getInbox(s);if(!d)return null;if(c){this.logger.verbose("Processing group conversation");let E=await this.waMonitor.waInstances[s.instanceName].client.groupMetadata(l);this.logger.verbose(Group metadata: ${JSON.stringify(E)}),u=${E.subject} (GROUP);let I=await this.waMonitor.waInstances[s.instanceName].profilePicture(e.key.participant.split("@")[0]);this.logger.verbose(Participant profile picture URL: ${JSON.stringify(I)});let T=await this.findContact(s,e.key.participant.split("@")[0]);this.logger.verbose(Found participant: ${JSON.stringify(T)}),T?(!T.name||T.name===l)&&await this.updateContact(s,T.id,{name:e.pushName,avatar_url:I.profilePictureUrl||null}):await this.createContact(s,e.key.participant.split("@")[0],d.id,!1,e.pushName,I.profilePictureUrl||null,e.key.participant)}let h=await this.waMonitor.waInstances[s.instanceName].profilePicture(l);this.logger.verbose(Contact profile picture URL: ${JSON.stringify(h)});let g=await this.findContact(s,l);if(g){if(this.logger.verbose(Found contact: ${JSON.stringify(g)}),!e.key.fromMe){let E=h?.profilePictureUrl?.split("#")[0].split("?")[0].split("/").pop()||"",I=g?.thumbnail?.split("#")[0].split("?")[0].split("/").pop()||"",T=E!==I,O=!g.name||g.name===l||(+${l}.startsWith("+55")?this.getNumbers(+${l}).some(L=>g.name===L||g.name===L.substring(3)||g.name===L.substring(1)):!1);this.logger.verbose(Picture needs update: ${T}),this.logger.verbose(Name needs update: ${O}),(T||O)&&(g=await this.updateContact(s,g.id,{...O&&{name:u},...E===""&&{avatar:null},...T&&{avatar_url:h?.profilePictureUrl}}))}}else g=await this.createContact(s,l,d.id,c,u,h.profilePictureUrl||null,o);if(!g)return this.logger.warn("Contact not created or found"),null;let m=g?.payload?.id||g?.payload?.contact?.id||g?.id;this.logger.verbose(Contact ID: ${m});let y=await a.contacts.listConversations({accountId:this.provider.accountId,id:m});if(this.logger.verbose(Contact conversations: ${JSON.stringify(y)}),!y||!y.payload)return this.logger.error("No conversations found or payload is undefined"),null;let w=y.payload.find(E=>E.inbox_id==d.id);if(w&&(this.provider.reopenConversation?(this.logger.verbose(Found conversation in reopenConversation mode: ${JSON.stringify(w)}),w&&this.provider.conversationPending&&w.status!=="open"&&await a.conversations.toggleStatus({accountId:this.provider.accountId,conversationId:w.id,data:{status:"pending"}})):(w=y.payload.find(E=>E&&E.status!=="resolved"&&E.inbox_id==d.id),this.logger.verbose(Found conversation: ${JSON.stringify(w)})),w))return this.logger.verbose(Returning existing conversation ID: ${w.id}),this.cache.set(n,w.id),w.id;let C={contact_id:m.toString(),inbox_id:d.id.toString()};if(this.provider.conversationPending&&(C.status="pending"),await this.cache.has(n))return await this.cache.get(n);let v=await a.conversations.create({accountId:this.provider.accountId,data:C});return v?(this.logger.verbose(New conversation created of ${o} with ID: ${v.id}),this.cache.set(n,v.id),v.id):(this.logger.warn("Conversation not created or found"),null)}finally{await this.cache.delete(i),this.logger.verbose(Block released for: ${i})}}catch(a){return this.logger.error(Error in createConversation: ${a}),null}}async getInbox(s){let e=${s.instanceName}:getInbox;if(await this.cache.has(e))return await this.cache.get(e);let t=await this.clientCw(s);if(!t)return this.logger.warn("client not found"),null;let o=await t.inboxes.list({accountId:this.provider.accountId});if(!o)return this.logger.warn("inbox not found"),null;let n=o.payload.find(i=>i.name===this.getClientCwConfig().nameInbox);return n?(this.cache.set(e,n),n):(this.logger.warn("inbox not found"),null)}async createMessage(s,e,t,o,n,i,r,a,c){let l=await this.clientCw(s);if(!l)return this.logger.warn("client not found"),null;let u=await this.getReplyToIds(r,s),d=c?.chatwootMessageId||null,h=await l.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:t,message_type:o,attachments:i,private:n||!1,source_id:a,content_attributes:{...u},source_reply_id:d?d.toString():null}});return h||(this.logger.warn("message not found"),null)}async getOpenConversationByContact(s,e,t){let o=await this.clientCw(s);return o?(await o.contacts.listConversations({accountId:this.provider.accountId,id:t.id})).payload.find(i=>i.inbox_id===e.id&&i.status==="open")||void 0:(this.logger.warn("client not found"),null)}async createBotMessage(s,e,t,o){let n=await this.clientCw(s);if(!n)return this.logger.warn("client not found"),null;let i=await this.findContact(s,"123456");if(!i)return this.logger.warn("contact not found"),null;let r=await this.getInbox(s);if(!r)return this.logger.warn("inbox not found"),null;let a=await this.getOpenConversationByContact(s,r,i);if(!a){this.logger.warn("conversation not found");return}let c=await n.messages.create({accountId:this.provider.accountId,conversationId:a.id,data:{content:e,message_type:t,attachments:o}});return c||(this.logger.warn("message not found"),null)}async sendData(s,e,t,o,n,i,r,a,c){if(a&&this.isImportHistoryAvailable()){let h=await X.getExistingSourceIds([a],s);if(h&&h.size>0)return this.logger.warn("Message already saved on chatwoot"),null}let l=new fn.default;n&&l.append("content",n),l.append("message_type",o),l.append("attachments[]",e,{filename:t});let u=c?.chatwootMessageId||null;if(r&&i){let h=await this.getReplyToIds(r,i);if(h.in_reply_to||h.in_reply_to_external_id){let g=JSON.stringify({...h});l.append("content_attributes",g)}}u&&l.append("source_reply_id",u.toString()),a&&l.append("source_id",a);let d={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${s}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:h}=await Rt.default.request(d);return h}catch(h){this.logger.error(h)}}async createBotQr(s,e,t,o,n){if(!await this.clientCw(s))return this.logger.warn("client not found"),null;if(!this.configService.get("CHATWOOT").BOT_CONTACT)return this.logger.log("Chatwoot bot contact is disabled"),!0;let r=await this.findContact(s,"123456");if(!r)return this.logger.warn("contact not found"),null;let a=await this.getInbox(s);if(!a)return this.logger.warn("inbox not found"),null;let c=await this.getOpenConversationByContact(s,a,r);if(!c){this.logger.warn("conversation not found");return}let l=new fn.default;e&&l.append("content",e),l.append("message_type",t),o&&n&&l.append("attachments[]",o,{filename:n});let u={method:"post",maxBodyLength:1/0,url:${this.provider.url}/api/v1/accounts/${this.provider.accountId}/conversations/${c.id}/messages,headers:{api_access_token:this.provider.token,...l.getHeaders()},data:l};try{let{data:d}=await Rt.default.request(u);return d}catch(d){this.logger.error(d)}}async sendAttachment(s,e,t,o,n){try{let i=wn.default.parse(decodeURIComponent(t)),r=ht.default.lookup(i?.ext)||"",a=i?.name+i?.ext;if(!r){let h=t.split("/");a=decodeURIComponent(h[h.length-1]),r=(await Rt.default.get(t,{responseType:"arraybuffer"})).headers["content-type"]}let c="document";switch(r.split("/")[0]){case"image":c="image";break;case"video":c="video";break;case"audio":c="audio";break;default:c="document";break}if(c==="audio"){let h={number:e,audio:t,delay:1200,quoted:n?.quoted};return j("/message/sendWhatsAppAudio"),await s?.audioWhatsapp(h,null,!0)}c==="image"&&i&&[".gif",".svg",".tiff",".tif"].includes(i?.ext)&&(c="document");let u={number:e,mediatype:c,fileName:a,media:t,delay:1200,quoted:n?.quoted};return j("/message/sendMedia"),o&&(u.caption=o),await s?.mediaMessage(u,null,!0)}catch(i){this.logger.error(i)}}async onSendMessageError(s,e,t){this.logger.verbose(onSendMessageError ${JSON.stringify(t)});let o=await this.clientCw(s);if(o){if(t&&t?.status===400&&t?.message[0]?.exists===!1){o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:${U.t("cw.message.numbernotinwhatsapp")},message_type:"outgoing",private:!0}});return}o.messages.create({accountId:this.provider.accountId,conversationId:e,data:{content:U.t("cw.message.notsent",{error:t?${t.toString()}:""}),message_type:"outgoing",private:!0}})}}async receiveWebhook(s,e){try{if(await new Promise(c=>setTimeout(c,500)),!await this.clientCw(s))return this.logger.warn("client not found"),null;if(this.provider.reopenConversation===!1&&e.event==="conversation_status_changed"&&e.status==="resolved"&&e.meta?.sender?.identifier){let c=${s.instanceName}:createConversation-${e.meta.sender.identifier};this.cache.delete(c)}if(!e?.conversation||e.private||e.event==="message_updated"&&!e.content_attributes?.deleted)return{message:"bot"};let o=e.conversation.meta.sender?.identifier||e.conversation.meta.sender?.phone_number.replace("+",""),n=e.content?e.content.replaceAll(/(?<!\*)\*((?!\s)([^\n*]+?)(?<!\s))\*(?!\*)/g,"_$1_").replaceAll(/\*{2}((?!\s)([^\n*]+?)(?<!\s))\*{2}/g,"*$1*").replaceAll(/~{2}((?!\s)([^\n*]+?)(?<!\s))~{2}/g,"~$1~").replaceAll(/(?<!)((?!\s)([^*]+?)(?<!\s))(?!)/g,"$1"):e.content,i=e?.conversation?.messages[0]?.sender?.available_name||e?.sender?.name,r=this.waMonitor.waInstances[s.instanceName];if(e.event==="message_updated"&&e.content_attributes?.deleted){let c=await this.prismaRepository.message.findFirst({where:{chatwootMessageId:e.id,instanceId:s.instanceId}});if(c){let l=c.key;await r?.client.sendMessage(l.remoteJid,{delete:l}),await this.prismaRepository.message.deleteMany({where:{instanceId:s.instanceId,chatwootMessageId:e.id}})}return{message:"bot"}}let a=this.configService.get("CHATWOOT").BOT_CONTACT;if(o==="123456"&&e.message_type==="outgoing"){let c=n.replace("/","");if(a&&(c.includes("init")||c.includes("iniciar")))if(r?.connectionStatus?.state!=="open"){let u=c.split(":")[1];await r.connectToWhatsapp(u)}else await this.createBotMessage(s,U.t("cw.inbox.alreadyConnected",{inboxName:e.inbox.name}),"incoming");if(c==="clearcache"&&(r.clearCacheChatwoot(),await this.createBotMessage(s,U.t("cw.inbox.clearCache",{inboxName:e.inbox.name}),"incoming")),c==="status"){let l=r?.connectionStatus?.state;l||await this.createBotMessage(s,U.t("cw.inbox.notFound",{inboxName:e.inbox.name}),"incoming"),l&&await this.createBotMessage(s,U.t("cw.inbox.status",{inboxName:e.inbox.name,state:l}),"incoming")}if(a&&(c==="disconnect"||c==="desconectar")){let l=U.t("cw.inbox.disconnect",{inboxName:e.inbox.name});await this.createBotMessage(s,l,"incoming"),await r?.client?.logout("Log out instance: "+s.instanceName),await r?.client?.ws?.close()}}if(e.message_type==="outgoing"&&e?.conversation?.messages?.length&&o!=="123456"){if(e?.conversation?.messages[0]?.source_id?.substring(0,5)==="WAID:")return{message:"bot"};if(!r&&e.conversation?.id)return this.onSendMessageError(s,e.conversation?.id,"Instance not found"),{message:"bot"};let c;if(i==null)c=n;else{let u=this.provider.signDelimiter?this.provider.signDelimiter.replaceAll("\n",`



`

85 ,d=this.provider.signMsg?[${i}:]:[];d.push(n),c=d.join(u)}for(let u of e.conversation.messages)if(u.attachments&&u.attachments.length>0)for(let d of u.attachments){n||(c=null);let h={quoted:await this.getQuotedMessage(e,s)},g=await this.sendAttachment(r,o,d.data_url,c,h);!g&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id),await this.updateChatwootMessageId({...g,owner:s.instanceName},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}else{let d={number:o,text:c,delay:1200,quoted:await this.getQuotedMessage(e,s)};j("/message/sendText");let h;try{if(h=await r?.textMessage(d,!0),!h)throw new Error("Message not sent");yn.default.isLong(h?.messageTimestamp)&&(h.messageTimestamp=h.messageTimestamp?.toNumber()),await this.updateChatwootMessageId({...h,instanceId:s.instanceId},{messageId:e.id,inboxId:e.inbox?.id,conversationId:e.conversation?.id,contactInboxSourceId:e.conversation?.contact_inbox?.source_id},s)}catch(g){throw!h&&e.conversation?.id&&this.onSendMessageError(s,e.conversation?.id,g),g}}if(this.configService.get("CHATWOOT").MESSAGE_READ){let u=await this.prismaRepository.message.findFirst({where:{key:{path:["fromMe"],equals:!1},instanceId:s.instanceId}});if(u&&!u.chatwootIsRead){let d=u.key;r?.markMessageAsRead({readMessages:[{id:d.id,fromMe:d.fromMe,remoteJid:d.remoteJid}]});let h={chatwootMessageId:u.chatwootMessageId,chatwootConversationId:u.chatwootConversationId,chatwootInboxId:u.chatwootInboxId,chatwootContactInboxSourceId:u.chatwootContactInboxSourceId,chatwootIsRead:!0};await this.prismaRepository.message.updateMany({where:{instanceId:s.instanceId,key:{path:["id"],equals:d.id}},data:h})}}}if(e.message_type==="template"&&e.event==="message_created"){let c={number:o,text:e.content.replace(/\\\r\n|\\\n|\n/g,

→ 86 `),delay:1200};j("/message/sendText"),await r?.textMessage(c)}return{message:"bot"}}catch(t){return this.logger.error(t),{message:"bot"}}}async updateChatwootMessageId(s,e,t){let o=s.key;!e.messageId||!o?.id||(await this.prismaRepository.message.updateMany(

Input error. A JSON path cannot be set without a scalar filter.

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7459)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async Pe.getMessageByKeyId (/evolution/dist/main.js:86:641)

at async Pe.eventWhatsapp (/evolution/dist/main.js:135:39) {

code: 'P2019',



{

modelName: 'Message',

details: 'A JSON path cannot be set without a scalar filter.'

},

clientVersion: '6.11.1'

}

recv 0 chats, 1000 contacts, 0 msgs (is latest: false, progress: 0%), type: 4

WanderleyGrecco avatar Sep 09 '25 17:09 WanderleyGrecco

Erro muito com a última versão de agora a tarde(15:21) @DavidsonGomes

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:26:53 INFO [ChannelStartupService] [string]

┌──────────────────────────────┐

│ CONNECTED TO WHATSAPP │

└──────────────────────────────┘

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:26:53 INFO [ChannelStartupService] [string]

    wuid: 556584012654                  

    name: wanderley

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:54 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:54 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:54 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:54 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:55 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:26:55 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 500 chats, 500 contacts, 652 msgs (is latest: true, progress: 0%), type: 0

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:27:01 LOG [ChannelStartupService] [string] Update messages [

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "3A3A1E84677FD47B2D79",

  "fromMe": false

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "A6EEC06A5AAA5DC9287C5BB6B9A7FE2F",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "F20FF4FFCFFAA0021EF741CB3CB37F96",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "C337407192EE5B506562E7CF35CAE51A",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "4F77843C881A6DA89D74B1CB125AC549",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "C9F5C0236825302C72AFAAC697730F3B",

  "fromMe": true

},

"update": {

  "starred": true

}

},

{

 "key": {

  "remoteJid": "[email protected]",

  "id": "A1D8067830B2E440DC9A9BFA2785300C",

  "fromMe": false

},

"update": {

  "starred": true

}

}

]

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 ERROR [unhandledRejection] [object]

{

origin: Promise {

<rejected> PrismaClientValidationError: 

Invalid `this.prismaRepository.messageUpdate.create()` invocation in

/evolution/dist/main.js:247:1170



  244   WHERE "instanceId" = ${this.instanceId} 

  245   AND "key"->>'id' = ${n.id}

  246   LIMIT 1

→ 247 `)[0]||null,u&&(l.messageId=u.id)),i.message===null&&i.status===void 0){this.sendDataWebhook("messages.delete",n),this.configService.get("DATABASE").SAVE_DATA.MESSAGE_UPDATE&&await this.prismaRepository.messageUpdate.create({

        data: {

          keyId: "3A3A1E84677FD47B2D79",

          remoteJid: "[email protected]",

          fromMe: false,

          participant: "[email protected]",

          status: "DELETED",

          pollUpdates: undefined,

          instanceId: "20bc89c1-eb27-4d3e-bae1-6373165e58f0",

      +   Message: {

      +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,

      +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,

      +     connect: MessageWhereUniqueInput

      +   }

        }

 })

Argument `Message` is missing.

    at kn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)

    at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7102)

    at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

    at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

    at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

    at async messages.update (/evolution/dist/main.js:247:1128) {

  clientVersion: '6.11.1'

}

},

stderr: 2

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 ERROR [unhandledRejection] [object]

PrismaClientValidationError:

Invalid this.prismaRepository.messageUpdate.create() invocation in

/evolution/dist/main.js:247:1170

244 WHERE "instanceId" = ${this.instanceId}

245 AND "key"->>'id' = ${n.id}

246 LIMIT 1

→ 247 `)[0]||null,u&&(l.messageId=u.id)),i.message===null&&i.status===void 0){this.sendDataWebhook("messages.delete",n),this.configService.get("DATABASE").SAVE_DATA.MESSAGE_UPDATE&&await this.prismaRepository.messageUpdate.create({

    data: {

      keyId: "3A3A1E84677FD47B2D79",

      remoteJid: "[email protected]",

      fromMe: false,

      participant: "[email protected]",

      status: "DELETED",

      pollUpdates: undefined,

      instanceId: "20bc89c1-eb27-4d3e-bae1-6373165e58f0",

  +   Message: {

  +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,

  +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,

  +     connect: MessageWhereUniqueInput

  +   }



}

  })

Argument Message is missing.

at kn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)

at Xn.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:7102)

at Xn.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6784)

at Xn.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6491)

at async l (/evolution/node_modules/@prisma/client/runtime/library.js:130:9812)

at async messages.update (/evolution/dist/main.js:247:1128) {

clientVersion: '6.11.1'

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:01 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:02 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:02 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 0 chats, 994 contacts, 0 msgs (is latest: false, progress: 0%), type: 4

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:02 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:02 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

2025/09/09 04:27PM 50 pid=190 hostname=3a7b7842eb0e key={"remoteJid":"[email protected]","fromMe":false,"id":"3FE2C29255C52AEF64B3","participant":"558695211166:[email protected]","participantAlt":"175539826495722:29@lid"} err={"type":"TypeError","message":"The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object","stack":"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object\n at Function.from (node:buffer:322:9)\n at SenderKeyState.getSigningKeyPublic (file:///evolution/node_modules/baileys/lib/Signal/Group/sender-key-state.js:61:23)\n at GroupCipher.decrypt (file:///evolution/node_modules/baileys/lib/Signal/Group/group_cipher.js:38:57)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async executeTransactionWork (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:293:24)\n at async Object.transaction (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:439:28)\n at async decrypt (file:///evolution/node_modules/baileys/lib/Utils/decode-wa-message.js:194:45)\n at async file:///evolution/node_modules/baileys/lib/Socket/messages-recv.js:962:21\n at async file:///evolution/node_modules/baileys/lib/Utils/make-mutex.js:16:36\n at async Promise.all (index 0)","code":"ERR_INVALID_ARG_TYPE"} messageType=skmsg [email protected] author=558695211166:[email protected] isSessionRecordError=false msg=failed to decrypt message

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:17 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:17 WARN [ChatwootService] [string] no body message found

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:27:17 LOG [ChannelStartupService] [string] Update not read messages [email protected]

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:27:17 LOG [ChannelStartupService] [object]

{

key: {

remoteJid: '[email protected]',

remoteJidAlt: undefined,

fromMe: false,

id: '3FE2C29255C52AEF64B3',

participant: '[email protected]',

participantAlt: '175539826495722:29@lid'

},

pushName: 'Diego - Webdesigner🧑🏾‍💻',

status: 'DELIVERY_ACK',

 message: {

senderKeyDistributionMessage: {

  groupId: '[email protected]',

  axolotlSenderKeyDistributionMessage: [Array]

},

messageContextInfo: { deviceListMetadata: [Object], deviceListMetadataVersion: 2 }

},

contextInfo: undefined,

messageType: 'unknown',

messageTimestamp: 1757449636,

instanceId: '20bc89c1-eb27-4d3e-bae1-6373165e58f0',

source: 'desktop'

}

Closing open session in favor of incoming prekey bundle

Closing session: SessionEntry {

 _chains: {

'Baqixt2v9ld7nv5VKgnKswV6+T9aJ7fnRaOWhX1xcLlm': { chainKey: [Object], chainType: 2, messageKeys: {} },

'BQQ0hRHmLj47+w5pcglPe9WpK8uZQuVvpFa+V6NAZ2QT': { chainKey: [Object], chainType: 1, messageKeys: {} }

},

registrationId: 1443570175,

currentRatchet: {

ephemeralKeyPair: {

  pubKey: <Buffer 05 04 34 85 11 e6 2e 3e 3b fb 0e 69 72 09 4f 7b d5 a9 2b cb 99 42 e5 6f a4 56 be 57 a3 40 67 64 13>,

  privKey: <Buffer a0 2c 60 4b 9d b6 bc 9b f7 80 d9 48 6c 8f 1e 4f de d8 5f 87 6b a6 8e 63 c3 fb fd 05 94 02 e8 47>

},

lastRemoteEphemeralKey: <Buffer 05 aa a2 c6 dd af f6 57 7b 9e fe 55 2a 09 ca b3 05 7a f9 3f 5a 27 b7 e7 45 a3 96 85 7d 71 70 b9 66>,

previousCounter: 0,

rootKey: <Buffer 29 5a 23 f1 5f ed de dd 7f 79 e2 bc e2 c8 a3 91 57 52 15 cb be f9 5b b7 b7 b1 60 d5 cb d3 de 68>

},

indexInfo: {

baseKey: <Buffer 05 28 a3 6f 70 2e c8 25 52 e5 21 9b ba 7b 4f e8 9f 45 34 03 3f 24 2c 39 48 b9 13 d5 2a bc ed fa 6d>,

baseKeyType: 2,

closed: -1,

used: 1757449637123,

created: 1757449637123,

remoteIdentityKey: <Buffer 05 48 c5 d1 eb f6 e7 fd ae d2 e7 e9 88 76 a1 31 cd 7a 2b 2e 66 72 12 4e 47 83 c8 74 25 e7 a8 50 56>

}

}

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:17 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 190 - Tue Sep 09 2025 17:27:17 LOG [ChannelStartupService] [string] Update messages [

{

 "key": {

  "remoteJid": "[email protected]",

  "fromMe": false,

  "id": "3F7013A5E0F8127895E8",

  "participant": "[email protected]",

  "participantAlt": "175539826495722:29@lid"

},

"update": {

  "message": {

    "editedMessage": {

      "message": {

        "conversation": "Opa Pessoal, beleza? Sei que aqui não é o espaço adequado, mas rodei um Subworkflow e deu um erro que não consegui resolver ainda\n\nEle diz \"O subfluxo de trabalho que você está tentando executar limita quais fluxos de trabalho podem ser chamados. Você precisará que Diego Silva atualize as configurações do subfluxo de trabalho (8qMBn988AQhiagVs) para permitir que este fluxo de trabalho o chame.\""

      }



}

  },

  "messageTimestamp": 1757449636

}

}

]

recv 35 chats, 50 contacts, 4718 msgs (is latest: false, progress: 21%), type: 3

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:18 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:19 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:20 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:20 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:25 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:25 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 31 chats, 44 contacts, 4904 msgs (is latest: false, progress: 43%), type: 3

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:29 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:29 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 160 chats, 160 contacts, 4968 msgs (is latest: false, progress: 65%), type: 3

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:40 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:40 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 80 chats, 90 contacts, 4958 msgs (is latest: false, progress: 87%), type: 3

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:50 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:50 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

recv 83 chats, 83 contacts, 2787 msgs (is latest: false, progress: 100%), type: 3

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:57 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:27:57 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:28:07 ERROR [ChatwootImport] [string] Error on import history contacts: error: ON CONFLICT DO UPDATE command cannot affect row a second time

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:28:07 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:28:07 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:28:08 VERBOSE [CacheEngine] [string] RedisCache initialized for Pe

[Evolution API] v2.3.3 190 - Tue Sep 09 2025 17:28:08 VERBOSE [CacheService] [string] cacheservice created using cache engine: Zt

WanderleyGrecco avatar Sep 09 '25 20:09 WanderleyGrecco

Teste realizado com imagem de hoje, estou tendo problema com mensagem de grupo:

[Evolution API] [wanderley] v2.3.3 177 - Wed Sep 10 2025 15:47:17 INFO [ChannelStartupService] [string] Message duplicated ignored [avoid deadlock]: 88f2f484-a1bc-4e55-964a-32beeac0898a_3EB05B17667C13F6E926A7_3

[Evolution API] [wanderley] v2.3.3 177 - Wed Sep 10 2025 15:47:17 INFO [ChannelStartupService] [string] Message duplicated ignored [avoid deadlock]: 88f2f484-a1bc-4e55-964a-32beeac0898a_3EB05AB7A6BD75991C6C84_3

2025/09/10 02:54PM 50 pid=177 hostname=4aa42df99627 key={"remoteJid":"[email protected]","fromMe":true,"id":"3EB0552EE1727C04C3260F","participant":"556584012654:[email protected]"} err={"type":"TypeError","message":"The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object","stack":"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object\n at Function.from (node:buffer:322:9)\n at SenderKeyState.getSigningKeyPublic (file:///evolution/node_modules/baileys/lib/Signal/Group/sender-key-state.js:64:23)\n at GroupCipher.decrypt (file:///evolution/node_modules/baileys/lib/Signal/Group/group_cipher.js:38:57)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async executeTransactionWork (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:293:24)\n at async Object.transaction (file:///evolution/node_modules/baileys/lib/Utils/auth-utils.js:439:28)\n at async decrypt (file:///evolution/node_modules/baileys/lib/Utils/decode-wa-message.js:194:45)\n at async file:///evolution/node_modules/baileys/lib/Socket/messages-recv.js:962:21\n at async file:///evolution/node_modules/baileys/lib/Utils/make-mutex.js:16:36\n at async Promise.all (index 0)","code":"ERR_INVALID_ARG_TYPE"} messageType=skmsg [email protected] author=556584012654:[email protected] isSessionRecordError=false msg=failed to decrypt message

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:01 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:01 WARN [ChatwootService] [string] no body message found

[Evolution API] [wanderley] v2.3.3 177 - Wed Sep 10 2025 15:54:01 LOG [ChannelStartupService] [string] Update readed messages [email protected] - 1757530441

[Evolution API] [wanderley] v2.3.3 177 - Wed Sep 10 2025 15:54:01 LOG [ChannelStartupService] [object]

{

key: {

remoteJid: '[email protected]',

remoteJidAlt: undefined,

fromMe: true,

id: '3EB0552EE1727C04C3260F',

participant: '[email protected]',

participantAlt: undefined

},

pushName: 'Wanderley Grecco',

status: 'SERVER_ACK',

 message: {

senderKeyDistributionMessage: {

  groupId: '[email protected]',

  axolotlSenderKeyDistributionMessage: [Array]

},

messageContextInfo: { deviceListMetadata: [Object], deviceListMetadataVersion: 2 }

},

contextInfo: undefined,

messageType: 'unknown',

messageTimestamp: 1757530441,

instanceId: '88f2f484-a1bc-4e55-964a-32beeac0898a',

source: 'web'

}

Closing open session in favor of incoming prekey bundle

Closing session: SessionEntry {

 _chains: {

'BQHoQh+mPNPY4ff/FnTJBrj2dtGZQm1Sd1YoScKwbWpM': { chainKey: [Object], chainType: 2, messageKeys: {} },

'BQTPKTgKtMaaFoPIUFHMmn+tlz5adwKGxFzYmCO1TJ8Q': { chainKey: [Object], chainType: 2, messageKeys: {} },

'BZWcAL46qL+KFNJ2RKc3xZfKbzZbdiN/mLUrrb1gsaI0': { chainKey: [Object], chainType: 1, messageKeys: {} }

},

registrationId: 12590,

currentRatchet: {

ephemeralKeyPair: {

  pubKey: <Buffer 05 95 9c 00 be 3a a8 bf 8a 14 d2 76 44 a7 37 c5 97 ca 6f 36 5b 76 23 7f 98 b5 2b ad bd 60 b1 a2 34>,

  privKey: <Buffer a8 53 83 38 a8 e9 aa 62 b7 b2 5e 3a 07 1b 16 b0 a7 a0 21 be 55 01 42 f4 96 2c 0b da 8f 18 d8 4b>

},

lastRemoteEphemeralKey: <Buffer 05 04 cf 29 38 0a b4 c6 9a 16 83 c8 50 51 cc 9a 7f ad 97 3e 5a 77 02 86 c4 5c d8 98 23 b5 4c 9f 10>,

previousCounter: 23,

rootKey: <Buffer 67 5b 7a 8d 8f 7c ce 16 b7 4f 38 ba 62 94 f4 1e a3 e9 64 3f d9 fd 68 fe e0 0d fb e7 f3 82 49 c8>

},

indexInfo: {

baseKey: <Buffer 05 64 f1 bd 20 04 1c fb e5 c0 d1 b5 dd f4 df f3 78 f4 27 9c 69 e4 34 14 86 65 24 b0 36 af 83 eb 45>,

baseKeyType: 1,

closed: -1,

used: 1757530441959,

created: 1757528523275,

remoteIdentityKey: <Buffer 05 49 0b e0 02 22 f9 39 be e2 c1 b9 e7 46 90 fe a7 44 53 6e 33 5e 2c d9 9e 81 47 e0 69 ab 3a ae 29>

}

}

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:03 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] [wanderley] v2.3.3 177 - Wed Sep 10 2025 15:54:03 INFO [ChannelStartupService] [string] Message duplicated ignored: 3EB0552EE1727C04C3260F

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:12 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:12 ERROR [ChatwootService] [object]

TypeError: Cannot read properties of null (reading 'key')

at Pe.eventWhatsapp (/evolution/dist/main.js:150:86) 

[Evolution API] v2.3.3 177 - Wed Sep 10 2025 15:54:13 LOG [BaileysMessageProcessor] [string] Processing batch of 1 messages

Message received from phone, id= 3EB0EB220DD58BF1EC0796 WebMessageInfo {

messageStubParameters: [],

labels: [],

userReceipt: [

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

},

UserReceipt {

  pendingDeviceJid: [],

  deliveredDeviceJid: [],

  userJid: '[email protected]',

  receiptTimestamp: [Long],

  readTimestamp: [Long],

  playedTimestamp: [Long]

}

],

reactions: [],

pollUpdates: [],

eventResponses: [],

statusMentions: [],

messageAddOns: [],

statusMentionSources: [],

supportAiCitations: [],

key: MessageKey {

remoteJid: '[email protected]',

fromMe: true,

id: '3EB0552EE1727C04C3260F'

},

message: Message {

conversation: 'Boa tarde, alguém aqui já colocou em produção zuckZapGo?'

},

messageTimestamp: Long { low: 1757530441, high: 0, unsigned: true },

 status: 2,

messageSecret: Uint8Array(32) [

237, 115, 155, 169,   7,   3, 189, 235,

227,  96,  33, 121, 135,  51,  31, 103,

104,  77,  32,  86, 120,  18, 195,  67,

 32,  56,  10,  84, 178, 216, 228, 188

WanderleyGrecco avatar Sep 10 '25 19:09 WanderleyGrecco

I was able to get a temporary fix by setting CACHE_REDIS_ENABLED to false and commenting out (#) redis setting. This was able to work. Does someone know a better way or is this the fix?

stevapps0 avatar Sep 11 '25 14:09 stevapps0

Olá! Estamos fazendo uma triagem do backlog para focar nos bugs reproduzíveis nas versões atuais.

Esta issue foi reportada em uma versão anterior do Evolution API, sem atividade recente. Nesse intervalo lançamos várias versões com correções e mudanças significativas no Baileys, na camada de webhooks e na integração com Cloud API.

Versões atuais:

  • Latest stable: v2.3.7 (Dezembro/2025)
  • Pre-release: 2.4.0-rc2 (Maio/2026) — recomendada para testar fixes mais recentes

Vamos fechar esta issue por inatividade. Se você ainda reproduz o problema na 2.3.7 ou na 2.4.0-rc2, por favor:

  1. Abra uma nova issue usando o template Bug Report
  2. Inclua: versão exata testada, passos para reproduzir, logs do servidor, payload de exemplo
  3. Linke esta issue na nova para preservar o histórico

Obrigado pela contribuição original e pela paciência!

DavidsonGomes avatar May 19 '26 14:05 DavidsonGomes