mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: implement "groupAcceptInviteV4" add participant msg
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types'
|
import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey, WAMessageStubType } from '../Types'
|
||||||
import { generateMessageID } from '../Utils'
|
import { generateMessageID, unixTimestampSeconds } from '../Utils'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, jidNormalizedUser } from '../WABinary'
|
||||||
import { makeSocket } from './socket'
|
import { makeSocket } from './socket'
|
||||||
|
|
||||||
export const makeGroupsSocket = (config: SocketConfig) => {
|
export const makeGroupsSocket = (config: SocketConfig) => {
|
||||||
const sock = makeSocket(config)
|
const sock = makeSocket(config)
|
||||||
const { query } = sock
|
const { authState, ev, query } = sock
|
||||||
|
|
||||||
const groupQuery = async(jid: string, type: 'get' | 'set', content: BinaryNode[]) => (
|
const groupQuery = async(jid: string, type: 'get' | 'set', content: BinaryNode[]) => (
|
||||||
query({
|
query({
|
||||||
@@ -139,18 +139,59 @@ export const makeGroupsSocket = (config: SocketConfig) => {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* accept a GroupInviteMessage
|
* accept a GroupInviteMessage
|
||||||
* @param senderJid jid of the person that sent the message
|
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
||||||
* @param inviteMessage the message to accept
|
* @param inviteMessage the message to accept
|
||||||
*/
|
*/
|
||||||
groupAcceptInviteV4: async(senderJid: string, inviteMessage: proto.IGroupInviteMessage) => {
|
groupAcceptInviteV4: async(key: string | WAMessageKey, inviteMessage: proto.IGroupInviteMessage) => {
|
||||||
|
key = typeof key === 'string' ? { remoteJid: key } : key
|
||||||
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
||||||
tag: 'accept',
|
tag: 'accept',
|
||||||
attrs: {
|
attrs: {
|
||||||
code: inviteMessage.inviteCode,
|
code: inviteMessage.inviteCode,
|
||||||
expiration: inviteMessage.inviteExpiration.toString(),
|
expiration: inviteMessage.inviteExpiration.toString(),
|
||||||
admin: senderJid
|
admin: key.remoteJid!
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
// if we have the full message key
|
||||||
|
// update the invite message to be expired
|
||||||
|
if(key.id) {
|
||||||
|
// create new invite message that is expired
|
||||||
|
inviteMessage = proto.GroupInviteMessage.fromObject(inviteMessage)
|
||||||
|
inviteMessage.inviteExpiration = 0
|
||||||
|
inviteMessage.inviteCode = ''
|
||||||
|
ev.emit('messages.update', [
|
||||||
|
{
|
||||||
|
key,
|
||||||
|
update: {
|
||||||
|
message: {
|
||||||
|
groupInviteMessage: inviteMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate the group add message
|
||||||
|
ev.emit('messages.upsert', {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
key: {
|
||||||
|
remoteJid: inviteMessage.groupJid,
|
||||||
|
id: generateMessageID(),
|
||||||
|
fromMe: false,
|
||||||
|
participant: key.remoteJid,
|
||||||
|
},
|
||||||
|
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
||||||
|
messageStubParameters: [
|
||||||
|
authState.creds.me!.id
|
||||||
|
],
|
||||||
|
participant: key.remoteJid,
|
||||||
|
messageTimestamp: unixTimestampSeconds()
|
||||||
|
}
|
||||||
|
],
|
||||||
|
type: 'notify'
|
||||||
|
})
|
||||||
|
|
||||||
return results.attrs.from
|
return results.attrs.from
|
||||||
},
|
},
|
||||||
groupGetInviteInfo: async(code: string) => {
|
groupGetInviteInfo: async(code: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user