mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Fix ContactsArrayMessage and add getBusinessProfile (#1074)
* Fix: ContactsArrayMessage and add getBusinessProfile * delete package-lock.json * edit readme.md * add bussines hours * make type same with leagcy * revert
This commit is contained in:
10
README.md
10
README.md
@@ -582,6 +582,11 @@ await sock.sendMessage(
|
|||||||
await sock.updateBlockStatus("xyz@s.whatsapp.net", "block") // Block user
|
await sock.updateBlockStatus("xyz@s.whatsapp.net", "block") // Block user
|
||||||
await sock.updateBlockStatus("xyz@s.whatsapp.net", "unblock") // Unblock user
|
await sock.updateBlockStatus("xyz@s.whatsapp.net", "unblock") // Unblock user
|
||||||
```
|
```
|
||||||
|
- To get a business profile, such as description, category
|
||||||
|
```ts
|
||||||
|
const profile = await sock.getBusinessProfile("xyz@s.whatsapp.net")
|
||||||
|
console.log("business description: " + profile.description + ", category: " + profile.category)
|
||||||
|
```
|
||||||
Of course, replace ``` xyz ``` with an actual ID.
|
Of course, replace ``` xyz ``` with an actual ID.
|
||||||
|
|
||||||
## Groups
|
## Groups
|
||||||
@@ -627,6 +632,11 @@ Of course, replace ``` xyz ``` with an actual ID.
|
|||||||
const code = await sock.groupInviteCode("abcd-xyz@g.us")
|
const code = await sock.groupInviteCode("abcd-xyz@g.us")
|
||||||
console.log("group code: " + code)
|
console.log("group code: " + code)
|
||||||
```
|
```
|
||||||
|
- To revoke the invite code in a group
|
||||||
|
```ts
|
||||||
|
const code = await sock.groupRevokeInvite("abcd-xyz@g.us")
|
||||||
|
console.log("New group code: " + code)
|
||||||
|
```
|
||||||
- To query the metadata of a group
|
- To query the metadata of a group
|
||||||
``` ts
|
``` ts
|
||||||
const metadata = await sock.groupMetadata("abcd-xyz@g.us")
|
const metadata = await sock.groupMetadata("abcd-xyz@g.us")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, AppStateChunk, LTHashState, ChatModification, Contact } from "../Types";
|
import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, AppStateChunk, LTHashState, ChatModification, Contact, WABusinessProfile, WABusinessHoursConfig } from "../Types";
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET, reduceBinaryNodeToDictionary } from "../WABinary";
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET, reduceBinaryNodeToDictionary } from "../WABinary";
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch, decodeSyncdSnapshot, newLTHashState } from "../Utils";
|
import { generateProfilePicture, toNumber, encodeSyncdPatch, decodePatches, extractSyncdPatches, chatModificationToAppPatch, decodeSyncdSnapshot, newLTHashState } from "../Utils";
|
||||||
@@ -159,6 +159,50 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getBusinessProfile = async (jid: string): Promise<WABusinessProfile | void> => {
|
||||||
|
const results = await query({
|
||||||
|
tag: 'iq',
|
||||||
|
attrs: {
|
||||||
|
to: 's.whatsapp.net',
|
||||||
|
xmlns: 'w:biz',
|
||||||
|
type: 'get'
|
||||||
|
},
|
||||||
|
content: [{
|
||||||
|
tag: 'business_profile',
|
||||||
|
attrs: { v: '244' },
|
||||||
|
content: [{
|
||||||
|
tag: 'profile',
|
||||||
|
attrs: { jid }
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
const profiles = getBinaryNodeChild(getBinaryNodeChild(results, 'business_profile'), 'profile')
|
||||||
|
if (!profiles) {
|
||||||
|
// if not bussines
|
||||||
|
if (logger.level == 'trace') logger.trace({ jid }, 'Not bussines')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const address = getBinaryNodeChild(profiles, 'address')
|
||||||
|
const description = getBinaryNodeChild(profiles, 'description')
|
||||||
|
const website = getBinaryNodeChild(profiles, 'website')
|
||||||
|
const email = getBinaryNodeChild(profiles, 'email')
|
||||||
|
const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category')
|
||||||
|
const business_hours = getBinaryNodeChild(profiles, 'business_hours')
|
||||||
|
const business_hours_config = business_hours && getBinaryNodeChildren(business_hours, 'business_hours_config')
|
||||||
|
return {
|
||||||
|
wid: profiles.attrs?.jid,
|
||||||
|
address: address?.content.toString(),
|
||||||
|
description: description?.content.toString(),
|
||||||
|
website: [website?.content.toString()],
|
||||||
|
email: email?.content.toString(),
|
||||||
|
category: category?.content.toString(),
|
||||||
|
business_hours: {
|
||||||
|
timezone: business_hours?.attrs?.timezone,
|
||||||
|
business_config: business_hours_config?.map(({ attrs }) => attrs as unknown as WABusinessHoursConfig)
|
||||||
|
}
|
||||||
|
} as unknown as WABusinessProfile
|
||||||
|
}
|
||||||
|
|
||||||
const updateAccountSyncTimestamp = async(fromTimestamp: number | string) => {
|
const updateAccountSyncTimestamp = async(fromTimestamp: number | string) => {
|
||||||
logger.info({ fromTimestamp }, 'requesting account sync')
|
logger.info({ fromTimestamp }, 'requesting account sync')
|
||||||
await sendNode({
|
await sendNode({
|
||||||
@@ -621,8 +665,9 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
fetchStatus,
|
fetchStatus,
|
||||||
updateProfilePicture,
|
updateProfilePicture,
|
||||||
updateBlockStatus,
|
updateBlockStatus,
|
||||||
|
getBusinessProfile,
|
||||||
resyncAppState,
|
resyncAppState,
|
||||||
chatModify,
|
chatModify,
|
||||||
resyncMainAppState,
|
resyncMainAppState,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ export type WAInitResponse = {
|
|||||||
status: 200
|
status: 200
|
||||||
}
|
}
|
||||||
|
|
||||||
type WABusinessHoursConfig = {
|
export type WABusinessHoursConfig = {
|
||||||
day_of_week: string
|
day_of_week: string
|
||||||
mode: string
|
mode: string
|
||||||
open_time?: number
|
open_time?: number
|
||||||
@@ -53,7 +53,7 @@ export type WABusinessProfile = {
|
|||||||
description: string
|
description: string
|
||||||
email: string
|
email: string
|
||||||
business_hours: {
|
business_hours: {
|
||||||
timezone: string
|
timezone?: string
|
||||||
config?: WABusinessHoursConfig[]
|
config?: WABusinessHoursConfig[]
|
||||||
business_config?: WABusinessHoursConfig[]
|
business_config?: WABusinessHoursConfig[]
|
||||||
}
|
}
|
||||||
@@ -65,4 +65,5 @@ export type WABusinessProfile = {
|
|||||||
wid?: string
|
wid?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type CurveKeyPair = { private: Uint8Array; public: Uint8Array }
|
export type CurveKeyPair = { private: Uint8Array; public: Uint8Array }
|
||||||
@@ -253,7 +253,7 @@ export const generateWAMessageContent = async(
|
|||||||
if(contactLen === 1) {
|
if(contactLen === 1) {
|
||||||
m.contactMessage = WAProto.ContactMessage.fromObject(message.contacts.contacts[0])
|
m.contactMessage = WAProto.ContactMessage.fromObject(message.contacts.contacts[0])
|
||||||
} else {
|
} else {
|
||||||
m.contactsArrayMessage = WAProto.ContactsArrayMessage.fromObject({ contacts: message.contacts })
|
m.contactsArrayMessage = WAProto.ContactsArrayMessage.fromObject(message.contacts)
|
||||||
}
|
}
|
||||||
} else if('location' in message) {
|
} else if('location' in message) {
|
||||||
m.locationMessage = WAProto.LocationMessage.fromObject(message.location)
|
m.locationMessage = WAProto.LocationMessage.fromObject(message.location)
|
||||||
|
|||||||
Reference in New Issue
Block a user