mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Fixed: loadMessages And isOnWhatsApp and Updated Readme (#573)
* LoadMessages And isOnWhatsApp fixed * Corrected Number Format Readme This error in readme caused android app to crash. * Updated Readme * Removed a Change for LoadMessages
This commit is contained in:
@@ -306,7 +306,7 @@ await conn.sendMessage(
|
||||
### Notes
|
||||
|
||||
- `id` is the WhatsApp ID of the person or group you're sending the message to.
|
||||
- It must be in the format ```[country code][phone number]@s.whatsapp.net```, for example ```+19999999999@s.whatsapp.net``` for people. For groups, it must be in the format ``` 123456789-123345@g.us ```.
|
||||
- It must be in the format ```[country code without +][phone number]@s.whatsapp.net```, for example ```19999999999@s.whatsapp.net``` for people. For groups, it must be in the format ``` 123456789-123345@g.us ```.
|
||||
- For broadcast lists it's `[timestamp of creation]@broadcast`.
|
||||
- For stories, the ID is `status@broadcast`.
|
||||
- For media messages, the thumbnail can be generated automatically for images & stickers. Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
|
||||
|
||||
@@ -19,33 +19,9 @@ export class WAConnection extends Base {
|
||||
* @returns undefined if the number doesn't exists, otherwise the correctly formatted jid
|
||||
*/
|
||||
isOnWhatsApp = async (str: string) => {
|
||||
if (this.state !== 'open') {
|
||||
return this.isOnWhatsAppNoConn(str)
|
||||
}
|
||||
const { status, jid, biz } = await this.query({json: ['query', 'exist', str], requiresPhoneConnection: false})
|
||||
if (status === 200) return { exists: true, jid: whatsappID(jid), isBusiness: biz as boolean}
|
||||
}
|
||||
/**
|
||||
* Query whether a given number is registered on WhatsApp, without needing to open a WS connection
|
||||
* @param str phone number/jid you want to check for
|
||||
* @returns undefined if the number doesn't exists, otherwise the correctly formatted jid
|
||||
*/
|
||||
isOnWhatsAppNoConn = async (str: string) => {
|
||||
let phone = str.split('@')[0]
|
||||
const url = `https://wa.me/${phone}`
|
||||
const response = await this.fetchRequest(url, 'GET', undefined, undefined, undefined, false)
|
||||
const loc = response.headers.location as string
|
||||
if (!loc) {
|
||||
this.logger.warn({ url, status: response.statusCode }, 'did not get location from request')
|
||||
return
|
||||
}
|
||||
const locUrl = new URL('', loc)
|
||||
if (!locUrl.pathname.endsWith('send/')) {
|
||||
return
|
||||
}
|
||||
phone = locUrl.searchParams.get('phone')
|
||||
return { exists: true, jid: `${phone}@s.whatsapp.net` }
|
||||
}
|
||||
/**
|
||||
* Tell someone about your presence -- online, typing, offline etc.
|
||||
* @param jid the ID of the person/group who you are updating
|
||||
|
||||
Reference in New Issue
Block a user