mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
usync, chat: get bot profile info and get bot list
This commit is contained in:
77
src/WAUSync/Protocols/UsyncBotProfileProtocol.ts
Normal file
77
src/WAUSync/Protocols/UsyncBotProfileProtocol.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { USyncQueryProtocol } from '../../Types/USync'
|
||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary'
|
||||
import { USyncUser } from '../USyncUser'
|
||||
|
||||
export type BotProfileCommand = {
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export type BotProfileInfo = {
|
||||
jid: string
|
||||
name: string
|
||||
attributes: string
|
||||
description: string
|
||||
category: string
|
||||
isDefault: boolean
|
||||
prompts: string[]
|
||||
personaId: string
|
||||
commands: BotProfileCommand[]
|
||||
commandsDescription: string
|
||||
}
|
||||
|
||||
export class USyncBotProfileProtocol implements USyncQueryProtocol {
|
||||
name = 'bot'
|
||||
|
||||
getQueryElement(): BinaryNode {
|
||||
return {
|
||||
tag: 'bot',
|
||||
attrs: { },
|
||||
content: [{ tag: 'profile', attrs: { v: '1' } }]
|
||||
}
|
||||
}
|
||||
|
||||
getUserElement(user: USyncUser): BinaryNode {
|
||||
return {
|
||||
tag: 'bot',
|
||||
attrs: { },
|
||||
content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
|
||||
}
|
||||
}
|
||||
|
||||
parser(node: BinaryNode): BotProfileInfo {
|
||||
const botNode = getBinaryNodeChild(node, 'bot')
|
||||
const profile = getBinaryNodeChild(botNode, 'profile')
|
||||
|
||||
const commandsNode = getBinaryNodeChild(profile, 'commands')
|
||||
const promptsNode = getBinaryNodeChild(profile, 'prompts')
|
||||
|
||||
const commands: BotProfileCommand[] = []
|
||||
const prompts: string[] = []
|
||||
|
||||
for(const command of getBinaryNodeChildren(commandsNode, 'command')) {
|
||||
commands.push({
|
||||
name: getBinaryNodeChildString(command, 'name')!,
|
||||
description: getBinaryNodeChildString(command, 'description')!
|
||||
})
|
||||
}
|
||||
|
||||
for(const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
|
||||
prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')!} ${getBinaryNodeChildString(prompt, 'text')!}`)
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
isDefault: !!getBinaryNodeChild(profile, 'default'),
|
||||
jid: node.attrs.jid,
|
||||
name: getBinaryNodeChildString(profile, 'name')!,
|
||||
attributes: getBinaryNodeChildString(profile, 'attributes')!,
|
||||
description: getBinaryNodeChildString(profile, 'description')!,
|
||||
category: getBinaryNodeChildString(profile, 'category')!,
|
||||
personaId: profile!.attrs['persona_id'],
|
||||
commandsDescription: getBinaryNodeChildString(commandsNode, 'description')!,
|
||||
commands,
|
||||
prompts
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ export class USyncUser {
|
||||
lid: string
|
||||
phone: string
|
||||
type: string
|
||||
personaId: string
|
||||
|
||||
withId(id: string) {
|
||||
this.id = id
|
||||
@@ -24,4 +25,8 @@ export class USyncUser {
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
withPersonaId(personaId: string) {
|
||||
this.personaId = personaId
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user