diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index d3458c5..789af5d 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -1,7 +1,7 @@ import { Boom } from '@hapi/boom' import { proto } from '../../WAProto' import { SignalRepository, WAMessageKey } from '../Types' -import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary' +import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidMetaIa, isJidNewsletter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary' import { unpadRandomMax16 } from './generics' import { ILogger } from './logger' @@ -47,22 +47,9 @@ export function decodeMessageNode( const isMe = (jid: string) => areJidsSameUser(jid, meId) const isMeLid = (jid: string) => areJidsSameUser(jid, meLid) - if(isJidUser(from)) { - if(recipient) { - if(!isMe(from)) { - throw new Boom('receipient present, but msg not from me', { data: stanza }) - } - - chatId = recipient - } else { - chatId = from - } - - msgType = 'chat' - author = from - } else if(isLidUser(from)) { - if(recipient) { - if(!isMeLid(from)) { + if(isJidUser(from) || isLidUser(from)) { + if(recipient && !isJidMetaIa(recipient)) { + if(!isMe(from) && !isMeLid(from)) { throw new Boom('receipient present, but msg not from me', { data: stanza }) } diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index a0e6139..202211e 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -46,6 +46,8 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => { export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefined) => ( jidDecode(jid1)?.user === jidDecode(jid2)?.user ) +/** is the jid Meta IA */ +export const isJidMetaIa = (jid: string | undefined) => (jid?.endsWith('@bot')) /** is the jid a user */ export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net')) /** is the jid a group */