From b0a7561726d69c94652af048bd5e701fb9dbe92a Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Tue, 27 Sep 2022 16:30:08 +0530 Subject: [PATCH] fix: jidNormalizedUser should not throw TypeError --- src/WABinary/jid-utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index d7e2634..840f770 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -53,7 +53,12 @@ export const isJidGroup = (jid: string | undefined) => (jid?.endsWith('@g.us')) /** is the jid the status broadcast */ export const isJidStatusBroadcast = (jid: string) => jid === 'status@broadcast' -export const jidNormalizedUser = (jid: string) => { - const { user, server } = jidDecode(jid)! +export const jidNormalizedUser = (jid: string | undefined) => { + const result = jidDecode(jid) + if(!result) { + return '' + } + + const { user, server } = result return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server as JidServer) } \ No newline at end of file