diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index e9e24aa..e9a7cde 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -191,7 +191,7 @@ export const makeGroupsSocket = (config: SocketConfig) => { ] ) const node = getBinaryNodeChild(result, action) - const participantsAffected = getBinaryNodeChildren(node!, 'participant') + const participantsAffected = getBinaryNodeChildren(node, 'participant') return participantsAffected.map(p => { return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p } }) @@ -232,6 +232,18 @@ export const makeGroupsSocket = (config: SocketConfig) => { const result = getBinaryNodeChild(results, 'group') return result?.attrs.jid }, + + /** + * revoke a v4 invite for someone + * @param groupJid group jid + * @param invitedJid jid of person you invited + * @returns true if successful + */ + groupRevokeInviteV4: async(groupJid: string, invitedJid: string) => { + const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]) + return !!result + }, + /** * accept a GroupInviteMessage * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 5d73086..490a59a 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -608,6 +608,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { return 'product' } else if(message.interactiveResponseMessage) { return 'native_flow_response' + } else if(message.groupInviteMessage) { + return 'url' } } @@ -746,6 +748,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { : undefined }, ), + //TODO: CACHE + getProfilePicUrl: sock.profilePictureUrl, upload: waUploadToServer, mediaCache: config.mediaCache, options: config.options, diff --git a/src/Types/Message.ts b/src/Types/Message.ts index 8c9a8f5..d0488cb 100644 --- a/src/Types/Message.ts +++ b/src/Types/Message.ts @@ -125,6 +125,14 @@ export type ButtonReplyInfo = { index: number } +export type GroupInviteInfo = { + inviteCode: string + inviteExpiration: number + text: string + jid: string + subject: string +} + export type WASendableProduct = Omit & { productImage: WAMediaUpload } @@ -153,6 +161,9 @@ export type AnyRegularMessageContent = ( buttonReply: ButtonReplyInfo type: 'template' | 'plain' } + | { + groupInvite: GroupInviteInfo + } | { listReply: Omit } @@ -244,6 +255,7 @@ export type MediaGenerationOptions = { } export type MessageContentGenerationOptions = MediaGenerationOptions & { getUrlInfo?: (text: string) => Promise + getProfilePicUrl?: (jid: string, type: 'image' | 'preview') => Promise } export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 82adbef..9293990 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -394,6 +394,25 @@ export const generateWAMessageContent = async( (message.disappearingMessagesInChat ? WA_DEFAULT_EPHEMERAL : 0) : message.disappearingMessagesInChat m = prepareDisappearingMessageSettingContent(exp) + } else if('groupInvite' in message) { + m.groupInviteMessage = {} + m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode + m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration + m.groupInviteMessage.caption = message.groupInvite.text + + m.groupInviteMessage.groupJid = message.groupInvite.jid + m.groupInviteMessage.groupName = message.groupInvite.subject + //TODO: use built-in interface and get disappearing mode info etc. + //TODO: cache / use store!? + if(options.getProfilePicUrl) { + const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview') + if(pfpUrl) { + const resp = await axios.get(pfpUrl, { responseType: 'arraybuffer' }) + if(resp.status === 200) { + m.groupInviteMessage.jpegThumbnail = resp.data + } + } + } } else if('pin' in message) { m.pinInChatMessage = {} m.messageContextInfo = {}