Closed cifumo closed 2 months ago
You mean sending channel admin invitation using bot?
You mean sending channel admin invitation using bot?
yess
Yeah you can
My code
const {
getBinaryNodeChild,
getBinaryNodeChildString,
generateWAMessageFromContent,
isLidUser,
S_WHATSAPP_NET
} = require('baileys')
const fetchUserLid = async (jid) => {
// based on https://github.com/WhiskeySockets/Baileys/blob/master/src/Socket/chats.ts#L142-L181
const [result] = await conn.sendInteractiveQuery([
{
tag: 'lid',
attrs: {}
}
], [
{
tag: 'user',
attrs: { jid }
}
])
if (result) {
const lid = getBinaryNodeChild(result, 'lid')
return lid.attrs.val
}
}
const getNewsletterInvite = async (newsletterJid, userLid) => {
const encoder = new TextEncoder()
const node = await conn.query({
tag: 'iq',
attrs: {
to: S_WHATSAPP_NET,
xmlns: 'w:mex',
type: 'get'
},
content: [{
tag: 'query',
attrs: { query_id: '6826078034173770' },
content: encoder.encode(JSON.stringify({
variables: {
newsletter_id: newsletterJid,
user_id: userLid
}
}))
}]
})
const result = JSON.parse(getBinaryNodeChildString(node, 'result'))
// if (result.errors) throw result.errors
return result.data['xwa2_newsletter_admin_invite_create']
}
const sendNewsletterAdminInvite = async (jid, content, options) => {
jid = isLidUser(jid) ? jid : await fetchUserLid(jid)
const inviteResp = await getNewsletterInvite(content.newsletter.jid, jid)
const fullMsg = await generateWAMessageFromContent(jid, {
newsletterAdminInviteMessage: {
newsletterJid: inviteResp.id,
newsletterName: content.newsletter.name,
jpegThumbnail: content.newsletter.thumbnail,
caption: content.newsletter.text,
inviteExpiration: inviteResp.invite_expiration_time
}
}, options)
await conn.relayMessage(jid, fullMsg.message, options)
return fullMsg
}
return sendNewsletterAdminInvite('xxx@s.whatsapp.net', {
newsletter: {
jid: 'xxx@newsletter',
name: 'Test',
text: 'Masuk gan',
thumbnail: Buffer.alloc(0) // customize your own thumbnail
}
}, {})
My code
const { getBinaryNodeChild, getBinaryNodeChildString, generateWAMessageFromContent, isLidUser, S_WHATSAPP_NET } = require('baileys') const fetchUserLid = async (jid) => { // based on https://github.com/WhiskeySockets/Baileys/blob/master/src/Socket/chats.ts#L142-L181 const [result] = await conn.sendInteractiveQuery([ { tag: 'lid', attrs: {} } ], [ { tag: 'user', attrs: { jid } } ]) if (result) { const lid = getBinaryNodeChild(result, 'lid') return lid.attrs.val } } const getNewsletterInvite = async (newsletterJid, userLid) => { const encoder = new TextEncoder() const node = await conn.query({ tag: 'iq', attrs: { to: S_WHATSAPP_NET, xmlns: 'w:mex', type: 'get' }, content: [{ tag: 'query', attrs: { query_id: '6826078034173770' }, content: encoder.encode(JSON.stringify({ variables: { newsletter_id: newsletterJid, user_id: userLid } })) }] }) const result = JSON.parse(getBinaryNodeChildString(node, 'result')) // if (result.errors) throw result.errors return result.data['xwa2_newsletter_admin_invite_create'] } const sendNewsletterAdminInvite = async (jid, content, options) => { jid = isLidUser(jid) ? jid : await fetchUserLid(jid) const inviteResp = await getNewsletterInvite(content.newsletter.jid, jid) const fullMsg = await generateWAMessageFromContent(jid, { newsletterAdminInviteMessage: { newsletterJid: inviteResp.id, newsletterName: content.newsletter.name, jpegThumbnail: content.newsletter.thumbnail, caption: content.newsletter.text, inviteExpiration: inviteResp.invite_expiration_time } }, options) await conn.relayMessage(jid, fullMsg.message, options) return fullMsg } return sendNewsletterAdminInvite('xxx@s.whatsapp.net', { newsletter: { jid: 'xxx@newsletter', name: 'Test', text: 'Masuk gan', thumbnail: Buffer.alloc(0) // customize your own thumbnail } }, {})
arigatoo
My code
const { getBinaryNodeChild, getBinaryNodeChildString, generateWAMessageFromContent, isLidUser, S_WHATSAPP_NET } = require('baileys') const fetchUserLid = async (jid) => { // based on https://github.com/WhiskeySockets/Baileys/blob/master/src/Socket/chats.ts#L142-L181 const [result] = await conn.sendInteractiveQuery([ { tag: 'lid', attrs: {} } ], [ { tag: 'user', attrs: { jid } } ]) if (result) { const lid = getBinaryNodeChild(result, 'lid') return lid.attrs.val } } const getNewsletterInvite = async (newsletterJid, userLid) => { const encoder = new TextEncoder() const node = await conn.query({ tag: 'iq', attrs: { to: S_WHATSAPP_NET, xmlns: 'w:mex', type: 'get' }, content: [{ tag: 'query', attrs: { query_id: '6826078034173770' }, content: encoder.encode(JSON.stringify({ variables: { newsletter_id: newsletterJid, user_id: userLid } })) }] }) const result = JSON.parse(getBinaryNodeChildString(node, 'result')) // if (result.errors) throw result.errors return result.data['xwa2_newsletter_admin_invite_create'] } const sendNewsletterAdminInvite = async (jid, content, options) => { jid = isLidUser(jid) ? jid : await fetchUserLid(jid) const inviteResp = await getNewsletterInvite(content.newsletter.jid, jid) const fullMsg = await generateWAMessageFromContent(jid, { newsletterAdminInviteMessage: { newsletterJid: inviteResp.id, newsletterName: content.newsletter.name, jpegThumbnail: content.newsletter.thumbnail, caption: content.newsletter.text, inviteExpiration: inviteResp.invite_expiration_time } }, options) await conn.relayMessage(jid, fullMsg.message, options) return fullMsg } return sendNewsletterAdminInvite('xxx@s.whatsapp.net', { newsletter: { jid: 'xxx@newsletter', name: 'Test', text: 'Masuk gan', thumbnail: Buffer.alloc(0) // customize your own thumbnail } }, {})
nooo error huhu
My code
const { getBinaryNodeChild, getBinaryNodeChildString, generateWAMessageFromContent, isLidUser, S_WHATSAPP_NET } = require('baileys') const fetchUserLid = async (jid) => { // based on https://github.com/WhiskeySockets/Baileys/blob/master/src/Socket/chats.ts#L142-L181 const [result] = await conn.sendInteractiveQuery([ { tag: 'lid', attrs: {} } ], [ { tag: 'user', attrs: { jid } } ]) if (result) { const lid = getBinaryNodeChild(result, 'lid') return lid.attrs.val } } const getNewsletterInvite = async (newsletterJid, userLid) => { const encoder = new TextEncoder() const node = await conn.query({ tag: 'iq', attrs: { to: S_WHATSAPP_NET, xmlns: 'w:mex', type: 'get' }, content: [{ tag: 'query', attrs: { query_id: '6826078034173770' }, content: encoder.encode(JSON.stringify({ variables: { newsletter_id: newsletterJid, user_id: userLid } })) }] }) const result = JSON.parse(getBinaryNodeChildString(node, 'result')) // if (result.errors) throw result.errors return result.data['xwa2_newsletter_admin_invite_create'] } const sendNewsletterAdminInvite = async (jid, content, options) => { jid = isLidUser(jid) ? jid : await fetchUserLid(jid) const inviteResp = await getNewsletterInvite(content.newsletter.jid, jid) const fullMsg = await generateWAMessageFromContent(jid, { newsletterAdminInviteMessage: { newsletterJid: inviteResp.id, newsletterName: content.newsletter.name, jpegThumbnail: content.newsletter.thumbnail, caption: content.newsletter.text, inviteExpiration: inviteResp.invite_expiration_time } }, options) await conn.relayMessage(jid, fullMsg.message, options) return fullMsg } return sendNewsletterAdminInvite('xxx@s.whatsapp.net', { newsletter: { jid: 'xxx@newsletter', name: 'Test', text: 'Masuk gan', thumbnail: Buffer.alloc(0) // customize your own thumbnail } }, {})
nooo error huhu
Yeah, because interactiveQuery function is not exported by baileys, so you have to create/export the function yourself
howwww