mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: implement tc token handling
TC token is required in certain cases to receive presence updates on chats
This commit is contained in:
@@ -494,14 +494,27 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
const presenceSubscribe = (toJid: string) => (
|
||||
/**
|
||||
* @param toJid the jid to subscribe to
|
||||
* @param tcToken token for subscription, use if present
|
||||
*/
|
||||
const presenceSubscribe = (toJid: string, tcToken?: Buffer) => (
|
||||
sendNode({
|
||||
tag: 'presence',
|
||||
attrs: {
|
||||
to: toJid,
|
||||
id: generateMessageTag(),
|
||||
type: 'subscribe'
|
||||
}
|
||||
},
|
||||
content: tcToken
|
||||
? [
|
||||
{
|
||||
tag: 'tctoken',
|
||||
attrs: { },
|
||||
content: tcToken
|
||||
}
|
||||
]
|
||||
: undefined
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -268,6 +268,21 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const from = jidNormalizedUser(node.attrs.from)
|
||||
|
||||
switch (nodeType) {
|
||||
case 'privacy_token':
|
||||
const tokenList = getBinaryNodeChildren(child, 'token')
|
||||
for(const { attrs, content } of tokenList) {
|
||||
const jid = attrs.jid
|
||||
ev.emit('chats.update', [
|
||||
{
|
||||
id: jid,
|
||||
tcToken: content as Buffer
|
||||
}
|
||||
])
|
||||
|
||||
logger.debug({ jid }, 'got privacy token update')
|
||||
}
|
||||
|
||||
break
|
||||
case 'w:gp2':
|
||||
handleGroupNotification(node.attrs.participant, child, result)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user