Skip to content

Commit

Permalink
send message do lid
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jan 28, 2025
1 parent 4f7ac88 commit fce31af
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ http://localhost:9876/v15.0/5549988290955/messages \
}'
```

To send a message to lid

```sh
curl -i -X POST \
http://localhost:9876/v15.0/5549988290955/messages \
-H 'Content-Type: application/json' \
-H 'Authorization: 1' \
-d '{
"messaging_product": "whatsapp",
"to": "206652636680324@lid",
"type": "text",
"text": {
"body": "hello"
}
}'
```

## Media

To test media
Expand Down
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.6",
"version": "1.26.0",
"description": "Unoapi Cloud",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion src/services/client_baileys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ export class ClientBaileys implements Client {
logger.debug('Quoted message %s!', JSON.stringify(quoted))
}
}
logger.debug('Send baileys from %s to %s -> %s', this.phone, to, JSON.stringify(content))
if (payload?.ttl) {
disappearingMessagesInChat = payload.ttl
}
Expand Down
5 changes: 2 additions & 3 deletions src/services/data_store_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
MessageUpsertType,
WAMessageUpdate,
GroupMetadata,
isJidGroup,
} from 'baileys'
import makeOrderedDictionary from 'baileys/lib/Store/make-ordered-dictionary'
import { BaileysInMemoryStoreConfig, waMessageID } from 'baileys/lib/Store/make-in-memory-store'
import { isSaveMedia, jidToPhoneNumber, phoneNumberToJid } from './transformer'
import { isIndividualJid, isSaveMedia, jidToPhoneNumber, phoneNumberToJid } from './transformer'
import { existsSync, readFileSync, rmSync, writeFileSync, mkdirSync } from 'fs'
import { DataStore, MessageStatus } from './data_store'
import { SESSION_DIR } from './session_store_file'
Expand Down Expand Up @@ -208,7 +207,7 @@ const dataStoreFile = async (phone: string, config: Config): Promise<DataStore>
ids.set(id, unoId)
}
dataStore.loadJid = async (phoneOrJid: string, sock: Partial<WASocket>) => {
if (isJidGroup(phoneOrJid)) {
if (!isIndividualJid(phoneOrJid)) {
return phoneOrJid
}
let jid = await dataStore.getJid(phoneOrJid)
Expand Down
2 changes: 1 addition & 1 deletion src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import makeWASocket, {
WAMessageKey,
delay,
proto,
isJidGroup,
WASocket,
AnyMessageContent,
BaileysEventMap,
Expand Down Expand Up @@ -397,6 +396,7 @@ export const connect = async ({
if (options.quoted) {
opts['quoted'] = options.quoted
}
logger.debug('Send baileys from %s to %s -> %s', phone, id, JSON.stringify(message))
return sock?.sendMessage(id, message, opts)
}
if (!isValidPhoneNumber(to)) {
Expand Down
7 changes: 5 additions & 2 deletions src/services/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyMessageContent, WAMessage, isJidUser, normalizeMessageContent, proto } from 'baileys'
import { AnyMessageContent, WAMessage, isJidUser, isLidUser, normalizeMessageContent, proto } from 'baileys'
import mime from 'mime-types'
import { parsePhoneNumber } from 'awesome-phonenumber'
import vCard from 'vcf'
Expand Down Expand Up @@ -300,7 +300,7 @@ export const phoneNumberToJid = (phoneNumber: string) => {
}

export const isIndividualJid = (jid: string) => {
const isIndividual = isJidUser(jid)
const isIndividual = isJidUser(jid) || jid.indexOf('@') < 0
logger.debug('jid %s is individual? %s', jid, isIndividual)
return isIndividual
}
Expand Down Expand Up @@ -390,6 +390,9 @@ export const isOutgoingMessage = (payload: object) => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const jidToPhoneNumber = (value: any, plus = '+', retry = true): string => {
if (isLidUser(value)) {
return value
}
const number = (value || '').split('@')[0].split(':')[0].replace('+', '')
const country = number.substring(0, 2)
if (country == '55') {
Expand Down

0 comments on commit fce31af

Please sign in to comment.