Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status 400 (Bad Request) ao enviar mensagem, mas a mensagem é enviada #978

Open
1 task done
CoToMax opened this issue Oct 14, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@CoToMax
Copy link

CoToMax commented Oct 14, 2024

Welcome!

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

What did you do?

Testei na versão 2.1.2 e 2.2.0-homolog, a mensagem é enviada mas retorna erro 400. Testei instalar do zero apagando o banco e o erro persiste.

Aparece this.prismaRepository.contact.findMany(), na versão 2.1.1 aparece este erro mas a mensagem não é enviada.

Log completo:

{
"status": 400,
"error": "Bad Request",
"response": {
"message": [
"PrismaClientUnknownRequestError: \nInvalid this.prismaRepository.contact.findMany() invocation in\n/evolution/dist/main.js:259:10347\n\n 256 wuid: ${r}\n 257 name: ${n}\n 258 ),await this.prismaRepository.instance.update({where:{id:this.instanceId},data:{ownerJid:this.instance.wuid,profileName:await this.getProfileName(),profilePicUrl:this.instance.profilePictureUrl,connectionStatus:\"open\"}}),this.configService.get(\"CHATWOOT\").ENABLED&&this.localChatwoot?.enabled&&(this.chatwootService.eventWhatsapp(\"connection.update\",{instanceName:this.instance.name,instanceId:this.instanceId},{instance:this.instance.name,status:\"open\"}),this.syncChatwootLostMessages())}}async getMessage(e,t=!1){try{let s=await this.prismaRepository.message.findMany({where:{instanceId:this.instanceId,key:{path:[\"id\"],equals:e.id}}});if(t)return s[0];if(s[0].message?.pollCreationMessage){let r=s[0].message?.messageContextInfo?.messageSecret;if(typeof r==\"string\")return{messageContextInfo:{messageSecret:Buffer.from(r,\"base64\")},pollCreationMessage:s[0].message?.pollCreationMessage}}return s[0].message}catch{return{conversation:\"\"}}}async defineAuthState(){let e=this.configService.get(\"DATABASE\"),t=this.configService.get(\"CACHE\");if(this.configService.get(\"PROVIDER\")?.ENABLED)return await this.authStateProvider.authStateProvider(this.instance.id);if(t?.REDIS.ENABLED&&t?.REDIS.SAVE_INSTANCES)return this.logger.info(\"Redis enabled\"),await lo(this.instance.id,this.cache);if(e.SAVE_DATA.INSTANCE)return await Hn(this.instance.id,this.cache)}async createClient(e){this.instance.authState=await this.defineAuthState();let t=this.configService.get(\"CONFIG_SESSION_PHONE\"),s={};if(e||this.phoneNumber)this.phoneNumber=e,this.logger.info(Phone number: ${e});else{let c=[t.CLIENT,t.NAME,(0,fo.release)()];s={browser:c},this.logger.info(Browser: ${c})}let r,n;t.VERSION?(r=t.VERSION.split(\".\"),n=Baileys version env: ${r}):(r=(await(0,R.fetchLatestBaileysVersion)()).version,n=Baileys version: ${r}),this.logger.info(n),this.logger.info(Group Ignore: ${this.localSettings.groupsIgnore});let o;if(this.localProxy?.enabled)if(this.logger.info(\"Proxy enabled: \"+this.localProxy?.host),this.localProxy?.host?.includes(\"proxyscrape\"))try{let g=(await _e.default.get(this.localProxy?.host)).data.split(\r\n→ 259 `),l=Math.floor(Math.random()Math.floor(g.length)),m="http://"+g[l];o={agent:ye(m),fetchAgent:ye(m)}}catch{this.localProxy.enabled=!1}else o={agent:ye({host:this.localProxy.host,port:this.localProxy.port,protocol:this.localProxy.protocol,username:this.localProxy.username,password:this.localProxy.password}),fetchAgent:ye({host:this.localProxy.host,port:this.localProxy.port,protocol:this.localProxy.protocol,username:this.localProxy.username,password:this.localProxy.password})};let a={...o,version:r,logger:(0,nt.default)({level:this.logBaileys}),printQRInTerminal:!1,auth:{creds:this.instance.authState.state.creds,keys:(0,R.makeCacheableSignalKeyStore)(this.instance.authState.state.keys,(0,nt.default)({level:"error"}))},msgRetryCounterCache:this.msgRetryCounterCache,generateHighQualityLinkPreview:!0,getMessage:async c=>await this.getMessage(c),...s,markOnlineOnConnect:this.localSettings.alwaysOnline,retryRequestDelayMs:350,maxMsgRetryCount:4,fireInitQueries:!0,connectTimeoutMs:3e4,keepAliveIntervalMs:3e4,qrTimeout:45e3,emitOwnEvents:!1,shouldIgnoreJid:c=>{let u=this.localSettings.groupsIgnore&&(0,R.isJidGroup)(c),g=!this.localSettings.readStatus&&(0,R.isJidBroadcast)(c),l=(0,R.isJidNewsletter)(c);return u||g||l},syncFullHistory:this.localSettings.syncFullHistory,shouldSyncHistoryMessage:c=>this.historySyncNotification(c),cachedGroupMetadata:this.getGroupMetadataCache,userDevicesCache:this.userDevicesCache,transactionOpts:{maxCommitRetries:10,delayBetweenTriesMs:3e3}};return this.endSession=!1,this.client=(0,R.default)(a),this.eventHandler(),this.phoneNumber=e,this.client}async connectToWhatsapp(e){try{return this.loadChatwoot(),this.loadSettings(),this.loadWebhook(),this.loadProxy(),await this.createClient(e)}catch(t){throw this.logger.error(t),new k(t?.toString())}}async reloadConnection(){try{return await this.createClient(this.phoneNumber)}catch(e){throw this.logger.error(e),new k(e?.toString())}}eventHandler(){this.client.ev.process(async e=>{if(!this.endSession){let t=this.configService.get("DATABASE"),s=await this.findSettings();if(e.call){let r=e.call[0];if(s?.rejectCall&&r.status=="offer"&&this.client.rejectCall(r.id,r.from),s?.msgCall?.trim().length>0&&r.status=="offer"){let n=await this.client.sendMessage(r.from,{text:s.msgCall});this.client.ev.emit("messages.upsert",{messages:[n],type:"notify"})}this.sendDataWebhook("call",r)}if(e["connection.update"]&&this.connectionUpdate(e["connection.update"]),e["creds.update"]&&this.instance.authState.saveCreds(),e["messaging-history.set"]){let r=e["messaging-history.set"];this.messageHandle"messaging-history.set"}if(e["messages.upsert"]){let r=e["messages.upsert"];this.messageHandle"messages.upsert"}if(e["messages.update"]){let r=e["messages.update"];this.messageHandle"messages.update"}if(e["message-receipt.update"]){let r=e["message-receipt.update"],n={};for(let o of r)typeof o.key.remoteJid=="string"&&typeof o.receipt.readTimestamp=="number"&&(n[o.key.remoteJid]=o.receipt.readTimestamp);await Promise.all(Object.keys(n).map(async o=>this.updateMessagesReadedByTimestamp(o,n[o])))}if(e["presence.update"]){let r=e["presence.update"];if(s?.groupsIgnore&&r.id.includes("@g.us"))return;this.sendDataWebhook("presence.update",r)}if(!s?.groupsIgnore){if(e["groups.upsert"]){let r=e["groups.upsert"];this.groupHandler"groups.upsert"}if(e["groups.update"]){let r=e["groups.update"];this.groupHandler"groups.update"}if(e["group-participants.update"]){let r=e["group-participants.update"];this.groupHandler"group-participants.update"}}if(e["chats.upsert"]){let r=e["chats.upsert"];this.chatHandle"chats.upsert"}if(e["chats.update"]){let r=e["chats.update"];this.chatHandle"chats.update"}if(e["chats.delete"]){let r=e["chats.delete"];this.chatHandle"chats.delete"}if(e["contacts.upsert"]){let r=e["contacts.upsert"];this.contactHandle"contacts.upsert"}if(e["contacts.update"]){let r=e["contacts.update"];this.contactHandle"contacts.update"}if(e["labels.association"]){let r=e["labels.association"];this.labelHandle"labels.association";return}if(e["labels.edit"]){let r=e["labels.edit"];this.labelHandle"labels.edit";return}}})}historySyncNotification(e){let t={instanceName:this.instance.name};return this.configService.get("CHATWOOT").ENABLED&&this.localChatwoot?.enabled&&this.localChatwoot.importMessages&&this.isSyncNotificationFromUsedSyncType(e)&&(e.chunkOrder===1&&this.chatwootService.startImportHistoryMessages(t),e.progress===100&&setTimeout(()=>{this.chatwootService.importHistoryMessages(t)},1e4)),!0}isSyncNotificationFromUsedSyncType(e){return this.localSettings.syncFullHistory&&e?.syncType===2||!this.localSettings.syncFullHistory&&e?.syncType===3}async profilePicture(e){let t=this.createJid(e);try{let s=await this.client.profilePictureUrl(t,"image");return{wuid:t,profilePictureUrl:s}}catch{return{wuid:t,profilePictureUrl:null}}}async getStatus(e){let t=this.createJid(e);try{return{wuid:t,status:(await this.client.fetchStatus(t))?.status}}catch{return{wuid:t,status:null}}}async fetchProfile(e,t){let s=t?this.createJid(t):this.client?.user?.id,r=(await this.whatsappNumber({numbers:[s]}))?.shift();if(!r.exists)throw new h(r);try{if(t){let n=(await this.whatsappNumber({numbers:[s]}))?.shift(),o=await this.profilePicture(n?.jid),a=await this.getStatus(n?.jid),c=await this.fetchBusinessProfile(n?.jid);return{wuid:n?.jid||s,name:n?.name,numberExists:n?.exists,picture:o?.profilePictureUrl,status:a?.status,isBusiness:c.isBusiness,email:c?.email,description:c?.description,website:c?.website?.shift()}}else{let n=await N.instanceInfo(e),o=await this.fetchBusinessProfile(s);return{wuid:s,name:n?.profileName,numberExists:!0,picture:n?.profilePicUrl,status:n?.connectionStatus,isBusiness:o.isBusiness,email:o?.email,description:o?.description,website:o?.website?.shift()}}}catch{return{wuid:s,name:null,picture:null,status:null,os:null,isBusiness:!1}}}async offerCall({number:e,isVideo:t,callDuration:s}){let r=this.createJid(e);try{let n=await this.client.offerCall(r,t);return setTimeout(()=>this.client.terminateCall(n.id,n.to),s1e3),n}catch(n){return n}}async sendMessage(e,t,s,r,n,o,a){e=e.toLowerCase();let c={quoted:n};if((0,R.isJidGroup)(e)&&(c.useCachedGroupMetadata=!0),a&&(c.ephemeralExpiration=a),o?c.messageId=o:c.messageId="3EB0"+(0,go.randomBytes)(18).toString("hex").toUpperCase(),!t.audio&&!t.poll&&!t.sticker&&!t.conversation&&e!=="status@broadcast"&&t.reactionMessage)return await this.client.sendMessage(e,{react:{text:t.reactionMessage.text,key:t.reactionMessage.key}},c);if(t.conversation)return await this.client.sendMessage(e,{text:t.conversation,mentions:s,linkPreview:r},c);if(!t.audio&&!t.poll&&!t.sticker&&e!="status@broadcast")return await this.client.sendMessage(e,{forward:{key:{remoteJid:this.instance.wuid,fromMe:!0},message:t},mentions:s},c);if(e==="status@broadcast"){let u;t.status.option.allContacts?u=(await this.prismaRepository.contact.findMany(\nError occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(MysqlError { code: 1366, message: "Incorrect integer value: 'PENDING' for column 'status' at row 1", state: "HY000" })), transient: false })"
]
}
}

What did you expect?

Retornar 200.

What did you observe instead of what you expected?

Retornar 400 mesmo com sucesso.

Screenshots/Videos

No response

Which version of the API are you using?

2.1.2 e 2.2.0-homolog.

What is your environment?

Windows

Other environment specifications

No response

If applicable, paste the log output

No response

Additional Notes

No response

@CoToMax CoToMax added the bug Something isn't working label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant