mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
update broadcast lists
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import BinaryNode from "../BinaryNode";
|
import BinaryNode from "../BinaryNode";
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { Chat, Contact, Presence, PresenceData, WABroadcastListInfo, SocketConfig, WAFlag, WAMetric, WABusinessProfile, ChatModification, WAMessageKey, WAMessage } from "../Types";
|
import { Chat, Contact, Presence, PresenceData, SocketConfig, WAFlag, WAMetric, WABusinessProfile, ChatModification, WAMessageKey, WAMessage } from "../Types";
|
||||||
import { debouncedTimeout, unixTimestampSeconds, whatsappID } from "../Utils/generics";
|
import { debouncedTimeout, unixTimestampSeconds, whatsappID } from "../Utils/generics";
|
||||||
import makeAuthSocket from "./auth";
|
import makeAuthSocket from "./auth";
|
||||||
import { Attributes, BinaryNode as BinaryNodeBase } from "../BinaryNode/types";
|
import { Attributes, BinaryNode as BinaryNodeBase } from "../BinaryNode/types";
|
||||||
@@ -413,14 +413,6 @@ const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
/** Query broadcast list info */
|
|
||||||
getBroadcastListInfo: (jid: string) => {
|
|
||||||
return query({
|
|
||||||
json: ['query', 'contact', jid],
|
|
||||||
expect200: true,
|
|
||||||
requiresPhoneConnection: true
|
|
||||||
}) as Promise<WABroadcastListInfo>
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Update the profile picture
|
* Update the profile picture
|
||||||
* @param jid
|
* @param jid
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import BinaryNode from "../BinaryNode";
|
import BinaryNode from "../BinaryNode";
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { SocketConfig, GroupModificationResponse, ParticipantAction, GroupMetadata, WAFlag, WAMetric, WAGroupCreateResponse, GroupParticipant } from "../Types";
|
import { SocketConfig, GroupModificationResponse, ParticipantAction, GroupMetadata, WAFlag, WAMetric, WAGroupCreateResponse, GroupParticipant } from "../Types";
|
||||||
import { generateMessageID, unixTimestampSeconds } from "../Utils/generics";
|
import { generateMessageID, unixTimestampSeconds, whatsappID } from "../Utils/generics";
|
||||||
import makeMessagesSocket from "./messages";
|
import makeMessagesSocket from "./messages";
|
||||||
|
|
||||||
const makeGroupsSocket = (config: SocketConfig) => {
|
const makeGroupsSocket = (config: SocketConfig) => {
|
||||||
@@ -47,8 +47,9 @@ const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
expect200: true
|
expect200: true
|
||||||
})
|
})
|
||||||
metadata.participants = metadata.participants.map(p => (
|
metadata.participants = metadata.participants.map(p => (
|
||||||
{ ...p, id: undefined, jid: p.jid }
|
{ ...p, id: undefined, jid: whatsappID(p.id) }
|
||||||
))
|
))
|
||||||
|
metadata.owner = whatsappID(metadata.owner)
|
||||||
return metadata as GroupMetadata
|
return metadata as GroupMetadata
|
||||||
}
|
}
|
||||||
/** Get the metadata (works after you've left the group also) */
|
/** Get the metadata (works after you've left the group also) */
|
||||||
@@ -153,7 +154,7 @@ const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
],
|
],
|
||||||
type: 'upsert'
|
type: 'upsert'
|
||||||
})
|
})
|
||||||
return response
|
return metadata
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Leave a group
|
* Leave a group
|
||||||
@@ -200,8 +201,33 @@ const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
const jids = Object.keys(result.participants || {})
|
const jids = Object.keys(result.participants || {})
|
||||||
ev.emit('group-participants.update', { jid, participants: jids, action })
|
ev.emit('group-participants.update', { jid, participants: jids, action })
|
||||||
return jids
|
return jids
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/** Query broadcast list info */
|
||||||
|
getBroadcastListInfo: async(jid: string) => {
|
||||||
|
interface WABroadcastListInfo {
|
||||||
|
status: number
|
||||||
|
name: string
|
||||||
|
recipients?: {id: string}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await query({
|
||||||
|
json: ['query', 'contact', jid],
|
||||||
|
expect200: true,
|
||||||
|
requiresPhoneConnection: true
|
||||||
|
}) as WABroadcastListInfo
|
||||||
|
|
||||||
|
const metadata: GroupMetadata = {
|
||||||
|
subject: result.name,
|
||||||
|
id: jid,
|
||||||
|
creation: undefined,
|
||||||
|
owner: getState().user?.jid,
|
||||||
|
participants: result.recipients!.map(({id}) => (
|
||||||
|
{ jid: whatsappID(id), isAdmin: false, isSuperAdmin: false }
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return metadata
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,6 +249,12 @@ export default(
|
|||||||
groupMetadata[jid] = await sock?.groupMetadata(jid, chats.get(jid)?.read_only === 'true')
|
groupMetadata[jid] = await sock?.groupMetadata(jid, chats.get(jid)?.read_only === 'true')
|
||||||
}
|
}
|
||||||
return groupMetadata[jid]
|
return groupMetadata[jid]
|
||||||
|
},
|
||||||
|
fetchBroadcastListInfo: async(jid: string, sock: Connection | undefined) => {
|
||||||
|
if(!groupMetadata[jid]) {
|
||||||
|
groupMetadata[jid] = await sock?.getBroadcastListInfo(jid)
|
||||||
|
}
|
||||||
|
return groupMetadata[jid]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,13 +137,6 @@ export type WAInitResponse = {
|
|||||||
status: 200
|
status: 200
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WABroadcastListInfo {
|
|
||||||
status: number
|
|
||||||
name: string
|
|
||||||
recipients?: {id: string}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type WABusinessHoursConfig = {
|
type WABusinessHoursConfig = {
|
||||||
day_of_week: string
|
day_of_week: string
|
||||||
mode: string
|
mode: string
|
||||||
|
|||||||
Reference in New Issue
Block a user