mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: catch groups create notification
This commit is contained in:
@@ -152,7 +152,7 @@ export const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const extractGroupMetadata = (result: BinaryNode) => {
|
export const extractGroupMetadata = (result: BinaryNode) => {
|
||||||
const group = getBinaryNodeChild(result, 'group')
|
const group = getBinaryNodeChild(result, 'group')
|
||||||
const descChild = getBinaryNodeChild(group, 'description')
|
const descChild = getBinaryNodeChild(group, 'description')
|
||||||
let desc: string | undefined
|
let desc: string | undefined
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
|
import { SocketConfig, WAMessageStubType, ParticipantAction, Chat, GroupMetadata } from "../Types"
|
||||||
import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils"
|
import { decodeMessageStanza, encodeBigEndian, toNumber, downloadHistory, generateSignalPubKey, xmppPreKey, xmppSignedPreKey } from "../Utils"
|
||||||
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, jidDecode, jidEncode, isJidStatusBroadcast, areJidsSameUser, getBinaryNodeChildren, jidNormalizedUser, getBinaryNodeChild } from '../WABinary'
|
||||||
import { proto } from "../../WAProto"
|
import { proto } from "../../WAProto"
|
||||||
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
import { KEY_BUNDLE_TYPE } from "../Defaults"
|
||||||
import { makeMessagesSocket } from "./messages-send"
|
import { makeMessagesSocket } from "./messages-send"
|
||||||
|
import { extractGroupMetadata } from "./groups"
|
||||||
|
|
||||||
const isReadReceipt = (type: string) => type === 'read' || type === 'read-self'
|
const isReadReceipt = (type: string) => type === 'read' || type === 'read-self'
|
||||||
|
|
||||||
@@ -216,7 +217,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
emitGroupUpdate({ restrict })
|
emitGroupUpdate({ restrict })
|
||||||
break
|
break
|
||||||
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
||||||
case WAMessageStubType.GROUP_CREATE:
|
|
||||||
chatUpdate.name = message.messageStubParameters[0]
|
chatUpdate.name = message.messageStubParameters[0]
|
||||||
emitGroupUpdate({ subject: chatUpdate.name })
|
emitGroupUpdate({ subject: chatUpdate.name })
|
||||||
break
|
break
|
||||||
@@ -270,6 +270,18 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
if(node.attrs.type === 'w:gp2') {
|
if(node.attrs.type === 'w:gp2') {
|
||||||
switch(child?.tag) {
|
switch(child?.tag) {
|
||||||
|
case 'create':
|
||||||
|
const metadata = extractGroupMetadata(child)
|
||||||
|
result.messageStubType = WAMessageStubType.GROUP_CREATE
|
||||||
|
result.messageStubParameters = [metadata.subject]
|
||||||
|
|
||||||
|
ev.emit('chats.upsert', [{
|
||||||
|
id: metadata.id,
|
||||||
|
name: metadata.subject,
|
||||||
|
conversationTimestamp: metadata.creation,
|
||||||
|
}])
|
||||||
|
ev.emit('groups.upsert', [metadata])
|
||||||
|
break
|
||||||
case 'ephemeral':
|
case 'ephemeral':
|
||||||
case 'not_ephemeral':
|
case 'not_ephemeral':
|
||||||
result.message = {
|
result.message = {
|
||||||
@@ -450,7 +462,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
ws.on('CB:notification', async(node: BinaryNode) => {
|
ws.on('CB:notification', async(node: BinaryNode) => {
|
||||||
const sendAck = async() => {
|
const sendAck = async() => {
|
||||||
await sendNode({
|
const stanza: BinaryNode = {
|
||||||
tag: 'ack',
|
tag: 'ack',
|
||||||
attrs: {
|
attrs: {
|
||||||
class: 'notification',
|
class: 'notification',
|
||||||
@@ -458,9 +470,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
type: node.attrs.type,
|
type: node.attrs.type,
|
||||||
to: node.attrs.from
|
to: node.attrs.from
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
if(node.attrs.participant) {
|
||||||
|
stanza.attrs.participant = node.attrs.participant
|
||||||
|
}
|
||||||
|
await sendNode(stanza)
|
||||||
|
|
||||||
logger.debug({ msgId: node.attrs.id }, 'ack notification')
|
logger.debug({ attrs: stanza.attrs }, 'ack notification')
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendAck()
|
await sendAck()
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ export type BaileysEventMap = {
|
|||||||
|
|
||||||
'message-info.update': MessageInfoUpdate[]
|
'message-info.update': MessageInfoUpdate[]
|
||||||
|
|
||||||
|
'groups.upsert': GroupMetadata[]
|
||||||
'groups.update': Partial<GroupMetadata>[]
|
'groups.update': Partial<GroupMetadata>[]
|
||||||
/** apply an action to participants in a group */
|
/** apply an action to participants in a group */
|
||||||
'group-participants.update': { id: string, participants: string[], action: ParticipantAction }
|
'group-participants.update': { id: string, participants: string[], action: ParticipantAction }
|
||||||
|
|||||||
Reference in New Issue
Block a user