Skip to content

Commit

Permalink
test if is individual to format jid
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jan 28, 2025
1 parent 5f6a8d6 commit 4f7ac88
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unoapi-cloud",
"version": "1.25.5",
"version": "1.25.6",
"description": "Unoapi Cloud",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/services/data_store_redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { proto, WAMessage, WAMessageKey, isJidUser, GroupMetadata } from 'baileys'
import { proto, WAMessage, WAMessageKey, GroupMetadata } from 'baileys'
import { DataStore, MessageStatus } from './data_store'
import { jidToPhoneNumber, phoneNumberToJid } from './transformer'
import { jidToPhoneNumber, phoneNumberToJid, isIndividualJid } from './transformer'
import { getDataStore, dataStores } from './data_store'
import { ONLY_HELLO_TEMPLATE } from '../defaults'
import {
Expand Down Expand Up @@ -82,13 +82,13 @@ const dataStoreRedis = async (phone: string, config: Config): Promise<DataStore>
await setJid(phone, phoneOrJid, jid)
}
store.loadMessage = async (remoteJid: string, id: string) => {
const newJid = isJidUser(remoteJid) ? phoneNumberToJid(jidToPhoneNumber(remoteJid)) : remoteJid
const newJid = isIndividualJid(remoteJid) ? phoneNumberToJid(jidToPhoneNumber(remoteJid)) : remoteJid
const m = await getMessage(phone, newJid, id)
const wm = m as proto.IWebMessageInfo
return wm
}
store.setMessage = async (remoteJid: string, message: WAMessage) => {
const newJid = isJidUser(remoteJid) ? phoneNumberToJid(jidToPhoneNumber(remoteJid)) : remoteJid
const newJid = isIndividualJid(remoteJid) ? phoneNumberToJid(jidToPhoneNumber(remoteJid)) : remoteJid
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return setMessage(phone, newJid, message.key.id!, message)
}
Expand Down
5 changes: 2 additions & 3 deletions src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import MAIN_LOGGER from 'baileys/lib/Utils/logger'
import { Config, defaultConfig } from './config'
import { Store } from './store'
import NodeCache from 'node-cache'
import { isValidPhoneNumber } from './transformer'
import { isIndividualJid, isValidPhoneNumber } from './transformer'
import logger from './logger'
import { Level } from 'pino'
import { SocksProxyAgent } from 'socks-proxy-agent'
Expand Down Expand Up @@ -380,8 +380,7 @@ export const connect = async ({
options: { composing: boolean; quoted: boolean | undefined } = { composing: false, quoted: undefined },
) => {
await validateStatus()

const id = isJidGroup(to) ? to : await exists(to)
const id = isIndividualJid(to) ? await exists(to) : to
if (id) {
if (options.composing) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/services/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export const jidToPhoneNumber = (value: any, plus = '+', retry = true): string =
}

export const jidToPhoneNumberIfUser = (value: any): string => {
return isJidUser(value) ? jidToPhoneNumber(value, '') : value
return isIndividualJid(value) ? jidToPhoneNumber(value, '') : value
}

/*
Expand Down

0 comments on commit 4f7ac88

Please sign in to comment.