@areumtecnologia/wasockets 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -25
- package/lib/Client/Builders/Buttons.js +127 -0
- package/lib/Client/Builders/EventBuilder.js +122 -0
- package/lib/Client/Builders/InteractiveMessage.js +150 -0
- package/lib/Client/Builders/Lists.js +78 -0
- package/lib/Client/Builders/PollBuilder.js +84 -0
- package/lib/Client/Builders/index.js +21 -0
- package/lib/Client/Constants.js +54 -0
- package/lib/Client/Context/CallContext.js +96 -0
- package/lib/Client/Context/MediaObject.js +155 -0
- package/lib/Client/Context/MessageContext.js +213 -0
- package/lib/Client/Modules/BusinessManager.js +155 -0
- package/lib/Client/Modules/ChannelManager.js +144 -0
- package/lib/Client/Modules/ChatManager.js +113 -0
- package/lib/Client/Modules/CommunityManager.js +136 -0
- package/lib/Client/Modules/GroupManager.js +194 -0
- package/lib/Client/Modules/LabelManager.js +123 -0
- package/lib/Client/Modules/MessageManager.js +198 -0
- package/lib/Client/Modules/PresenceManager.js +68 -0
- package/lib/Client/Modules/PrivacyManager.js +98 -0
- package/lib/Client/Modules/ProfileManager.js +92 -0
- package/lib/Client/Modules/UserManager.js +92 -0
- package/lib/Client/Modules/VoipManager.js +117 -0
- package/lib/Client/Modules/index.js +29 -0
- package/lib/Client/Normalizers/EventNormalizer.js +99 -0
- package/lib/Client/Normalizers/JidNormalizer.js +96 -0
- package/lib/Client/Normalizers/MessageNormalizer.js +422 -0
- package/lib/Client/WaClient.js +438 -0
- package/lib/Client/index.d.ts +547 -0
- package/lib/Client/index.js +76 -0
- package/package.json +29 -23
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { JidNormalizer } = require("../Normalizers/JidNormalizer")
|
|
6
|
+
|
|
7
|
+
class BusinessManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../WaClient').WaClient} client
|
|
10
|
+
*/
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getSock() {
|
|
16
|
+
if (!this.client.sock) {
|
|
17
|
+
throw new Error('Socket is not connected.')
|
|
18
|
+
}
|
|
19
|
+
return this.client.sock
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Cria um produto no catálogo comercial
|
|
24
|
+
* @param {Object} product
|
|
25
|
+
* @param {string} product.name
|
|
26
|
+
* @param {string} [product.description]
|
|
27
|
+
* @param {number} product.price
|
|
28
|
+
* @param {string} [product.currency='BRL']
|
|
29
|
+
* @param {Array<string|Buffer>} [product.images=[]]
|
|
30
|
+
* @param {string} [product.retailerId]
|
|
31
|
+
* @param {string} [product.url]
|
|
32
|
+
* @param {boolean} [product.isHidden=false]
|
|
33
|
+
*/
|
|
34
|
+
async createProduct(product) {
|
|
35
|
+
const sock = this._getSock()
|
|
36
|
+
if (!sock.productCreate) {
|
|
37
|
+
throw new Error('productCreate indisponível no socket.')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const formattedImages = (product.images || []).map(img => (
|
|
41
|
+
typeof img === 'string' ? { url: img } : img
|
|
42
|
+
))
|
|
43
|
+
|
|
44
|
+
const payload = {
|
|
45
|
+
name: product.name,
|
|
46
|
+
description: product.description || '',
|
|
47
|
+
price: Math.round((Number(product.price) || 0) * 1000), // Preço em milésimos
|
|
48
|
+
currency: product.currency || 'BRL',
|
|
49
|
+
images: formattedImages,
|
|
50
|
+
retailerId: product.retailerId || undefined,
|
|
51
|
+
url: product.url || undefined,
|
|
52
|
+
isHidden: Boolean(product.isHidden)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return sock.productCreate(payload)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Atualiza dados de um produto existente no catálogo
|
|
60
|
+
* @param {string} productId
|
|
61
|
+
* @param {Object} update
|
|
62
|
+
*/
|
|
63
|
+
async updateProduct(productId, update = {}) {
|
|
64
|
+
const sock = this._getSock()
|
|
65
|
+
if (!sock.productUpdate) {
|
|
66
|
+
throw new Error('productUpdate indisponível no socket.')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const payload = { ...update }
|
|
70
|
+
if (typeof update.price !== 'undefined') {
|
|
71
|
+
payload.price = Math.round((Number(update.price) || 0) * 1000)
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(update.images)) {
|
|
74
|
+
payload.images = update.images.map(img => (
|
|
75
|
+
typeof img === 'string' ? { url: img } : img
|
|
76
|
+
))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return sock.productUpdate(productId, payload)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Exclui um ou mais produtos do catálogo
|
|
84
|
+
* @param {string|string[]} productIds
|
|
85
|
+
* @returns {Promise<{ deleted: number }>}
|
|
86
|
+
*/
|
|
87
|
+
async deleteProduct(productIds) {
|
|
88
|
+
const sock = this._getSock()
|
|
89
|
+
if (!sock.productDelete) {
|
|
90
|
+
throw new Error('productDelete indisponível no socket.')
|
|
91
|
+
}
|
|
92
|
+
const ids = Array.isArray(productIds) ? productIds : [productIds]
|
|
93
|
+
return sock.productDelete(ids)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Obtém detalhes de um produto específico
|
|
98
|
+
* @param {string} productId
|
|
99
|
+
* @param {string} [merchantJid] - JID da empresa (ou self se omitido)
|
|
100
|
+
*/
|
|
101
|
+
async getProduct(productId, merchantJid) {
|
|
102
|
+
const sock = this._getSock()
|
|
103
|
+
if (!sock.getProduct) {
|
|
104
|
+
throw new Error('getProduct indisponível no socket.')
|
|
105
|
+
}
|
|
106
|
+
const targetJid = merchantJid ? JidNormalizer.toJid(merchantJid) : undefined
|
|
107
|
+
return sock.getProduct(targetJid, productId)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Lista produtos do catálogo
|
|
112
|
+
* @param {Object} [options={}]
|
|
113
|
+
* @param {string} [options.jid] - JID do comerciante
|
|
114
|
+
* @param {number} [options.limit=20]
|
|
115
|
+
* @param {string} [options.cursor]
|
|
116
|
+
*/
|
|
117
|
+
async getCatalog(options = {}) {
|
|
118
|
+
const sock = this._getSock()
|
|
119
|
+
if (!sock.getCatalog) {
|
|
120
|
+
throw new Error('getCatalog indisponível no socket.')
|
|
121
|
+
}
|
|
122
|
+
const jid = options.jid ? JidNormalizer.toJid(options.jid) : undefined
|
|
123
|
+
return sock.getCatalog({ ...options, jid })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Lista coleções de produtos
|
|
128
|
+
* @param {string} [merchantJid]
|
|
129
|
+
* @param {number} [limit=20]
|
|
130
|
+
*/
|
|
131
|
+
async getCollections(merchantJid, limit = 20) {
|
|
132
|
+
const sock = this._getSock()
|
|
133
|
+
if (!sock.getCollections) {
|
|
134
|
+
throw new Error('getCollections indisponível no socket.')
|
|
135
|
+
}
|
|
136
|
+
const targetJid = merchantJid ? JidNormalizer.toJid(merchantJid) : undefined
|
|
137
|
+
return sock.getCollections(targetJid, limit)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Obtém os detalhes de um pedido de checkout
|
|
142
|
+
* @param {string} orderId
|
|
143
|
+
* @param {string} orderToken - Token base64 do pedido
|
|
144
|
+
*/
|
|
145
|
+
async getOrderDetails(orderId, orderToken) {
|
|
146
|
+
const sock = this._getSock()
|
|
147
|
+
if (!sock.getOrderDetails) {
|
|
148
|
+
throw new Error('getOrderDetails indisponível no socket.')
|
|
149
|
+
}
|
|
150
|
+
return sock.getOrderDetails(orderId, orderToken)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
exports.BusinessManager = BusinessManager
|
|
155
|
+
exports.default = BusinessManager
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { JidNormalizer } = require("../Normalizers/JidNormalizer")
|
|
6
|
+
|
|
7
|
+
class ChannelManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../WaClient').WaClient} client
|
|
10
|
+
*/
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getSock() {
|
|
16
|
+
if (!this.client.sock) {
|
|
17
|
+
throw new Error('Socket is not connected.')
|
|
18
|
+
}
|
|
19
|
+
return this.client.sock
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Cria um novo canal / Newsletter
|
|
24
|
+
* @param {string} name
|
|
25
|
+
* @param {string} [description='']
|
|
26
|
+
*/
|
|
27
|
+
async create(name, description = '') {
|
|
28
|
+
const sock = this._getSock()
|
|
29
|
+
return sock.newsletterCreate(name, description)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Obtém metadados de um canal por JID ou código de convite
|
|
34
|
+
* @param {string} channelJidOrInvite
|
|
35
|
+
*/
|
|
36
|
+
async getMetadata(channelJidOrInvite) {
|
|
37
|
+
const sock = this._getSock()
|
|
38
|
+
const isInvite = !channelJidOrInvite.includes('@')
|
|
39
|
+
const type = isInvite ? 'invite' : 'jid'
|
|
40
|
+
return sock.newsletterMetadata(type, channelJidOrInvite)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Segue / Inscreve-se em um canal
|
|
45
|
+
* @param {string} channelJid
|
|
46
|
+
*/
|
|
47
|
+
async subscribe(channelJid) {
|
|
48
|
+
const sock = this._getSock()
|
|
49
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
50
|
+
return sock.newsletterFollow(targetJid)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Deixa de seguir um canal
|
|
55
|
+
* @param {string} channelJid
|
|
56
|
+
*/
|
|
57
|
+
async unsubscribe(channelJid) {
|
|
58
|
+
const sock = this._getSock()
|
|
59
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
60
|
+
return sock.newsletterUnfollow(targetJid)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Silencia notificações do canal
|
|
65
|
+
* @param {string} channelJid
|
|
66
|
+
*/
|
|
67
|
+
async mute(channelJid) {
|
|
68
|
+
const sock = this._getSock()
|
|
69
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
70
|
+
return sock.newsletterMute(targetJid)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reativa notificações do canal
|
|
75
|
+
* @param {string} channelJid
|
|
76
|
+
*/
|
|
77
|
+
async unmute(channelJid) {
|
|
78
|
+
const sock = this._getSock()
|
|
79
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
80
|
+
return sock.newsletterUnmute(targetJid)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Retorna a lista de todos os canais inscritos da conta
|
|
85
|
+
*/
|
|
86
|
+
async listSubscribed() {
|
|
87
|
+
const sock = this._getSock()
|
|
88
|
+
return sock.newsletterSubscribed()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Busca mensagens recentes do canal
|
|
93
|
+
* @param {string} channelJid
|
|
94
|
+
* @param {number} [count=20]
|
|
95
|
+
* @param {number} [sinceTimestamp]
|
|
96
|
+
*/
|
|
97
|
+
async fetchMessages(channelJid, count = 20, sinceTimestamp) {
|
|
98
|
+
const sock = this._getSock()
|
|
99
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
100
|
+
if (!sock.newsletterFetchMessages) {
|
|
101
|
+
throw new Error('newsletterFetchMessages indisponível no socket.')
|
|
102
|
+
}
|
|
103
|
+
return sock.newsletterFetchMessages(targetJid, count, sinceTimestamp)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Busca as reações de uma mensagem do canal
|
|
108
|
+
* @param {string} channelJid
|
|
109
|
+
* @param {string} messageServerId
|
|
110
|
+
*/
|
|
111
|
+
async fetchReactions(channelJid, messageServerId) {
|
|
112
|
+
const sock = this._getSock()
|
|
113
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
114
|
+
if (!sock.newsletterFetchReactions) {
|
|
115
|
+
throw new Error('newsletterFetchReactions indisponível no socket.')
|
|
116
|
+
}
|
|
117
|
+
return sock.newsletterFetchReactions(targetJid, messageServerId)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Altera o nome do canal
|
|
122
|
+
* @param {string} channelJid
|
|
123
|
+
* @param {string} name
|
|
124
|
+
*/
|
|
125
|
+
async setName(channelJid, name) {
|
|
126
|
+
const sock = this._getSock()
|
|
127
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
128
|
+
return sock.newsletterUpdate(targetJid, { name })
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Altera a descrição do canal
|
|
133
|
+
* @param {string} channelJid
|
|
134
|
+
* @param {string} description
|
|
135
|
+
*/
|
|
136
|
+
async setDescription(channelJid, description) {
|
|
137
|
+
const sock = this._getSock()
|
|
138
|
+
const targetJid = JidNormalizer.toJid(channelJid)
|
|
139
|
+
return sock.newsletterUpdate(targetJid, { description })
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
exports.ChannelManager = ChannelManager
|
|
144
|
+
exports.default = ChannelManager
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { JidNormalizer } = require("../Normalizers/JidNormalizer")
|
|
6
|
+
|
|
7
|
+
class ChatManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../WaClient').WaClient} client
|
|
10
|
+
*/
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getSock() {
|
|
16
|
+
if (!this.client.sock) {
|
|
17
|
+
throw new Error('Socket is not connected.')
|
|
18
|
+
}
|
|
19
|
+
return this.client.sock
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fixa a conversa no topo
|
|
24
|
+
* @param {string} jid
|
|
25
|
+
*/
|
|
26
|
+
async pin(jid) {
|
|
27
|
+
const sock = this._getSock()
|
|
28
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
29
|
+
return sock.chatModify({ pin: true }, targetJid)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Desafixa a conversa do topo
|
|
34
|
+
* @param {string} jid
|
|
35
|
+
*/
|
|
36
|
+
async unpin(jid) {
|
|
37
|
+
const sock = this._getSock()
|
|
38
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
39
|
+
return sock.chatModify({ pin: false }, targetJid)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Silencia notificações do chat
|
|
44
|
+
* @param {string} jid
|
|
45
|
+
* @param {number} [durationMs=86400000] - Duração em ms (padrão: 24h, null para permanente)
|
|
46
|
+
*/
|
|
47
|
+
async mute(jid, durationMs = 86400000) {
|
|
48
|
+
const sock = this._getSock()
|
|
49
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
50
|
+
return sock.chatModify({ mute: durationMs }, targetJid)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Reativa o som do chat
|
|
55
|
+
* @param {string} jid
|
|
56
|
+
*/
|
|
57
|
+
async unmute(jid) {
|
|
58
|
+
const sock = this._getSock()
|
|
59
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
60
|
+
return sock.chatModify({ mute: null }, targetJid)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Arquiva uma conversa
|
|
65
|
+
* @param {string} jid
|
|
66
|
+
*/
|
|
67
|
+
async archive(jid) {
|
|
68
|
+
const sock = this._getSock()
|
|
69
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
70
|
+
return sock.chatModify({ archive: true }, targetJid)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Desarquiva uma conversa
|
|
75
|
+
* @param {string} jid
|
|
76
|
+
*/
|
|
77
|
+
async unarchive(jid) {
|
|
78
|
+
const sock = this._getSock()
|
|
79
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
80
|
+
return sock.chatModify({ archive: false }, targetJid)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Marca ou desmarca o chat como favorito
|
|
85
|
+
* @param {string} jid
|
|
86
|
+
* @param {boolean} [isFavorite=true]
|
|
87
|
+
*/
|
|
88
|
+
async setFavorite(jid, isFavorite = true) {
|
|
89
|
+
const sock = this._getSock()
|
|
90
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
91
|
+
if (!sock.updateFavorite) {
|
|
92
|
+
throw new Error('updateFavorite indisponível no socket.')
|
|
93
|
+
}
|
|
94
|
+
return sock.updateFavorite(targetJid, isFavorite)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Salva uma anotação interna no contato (recurso exclusivo WaSockets)
|
|
99
|
+
* @param {string} jid
|
|
100
|
+
* @param {string} note
|
|
101
|
+
*/
|
|
102
|
+
async setChatNote(jid, note) {
|
|
103
|
+
const sock = this._getSock()
|
|
104
|
+
const targetJid = JidNormalizer.toJid(jid)
|
|
105
|
+
if (!sock.updateChatNote) {
|
|
106
|
+
throw new Error('updateChatNote indisponível no socket.')
|
|
107
|
+
}
|
|
108
|
+
return sock.updateChatNote(targetJid, note)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.ChatManager = ChatManager
|
|
113
|
+
exports.default = ChatManager
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { JidNormalizer } = require("../Normalizers/JidNormalizer")
|
|
6
|
+
|
|
7
|
+
class CommunityManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../WaClient').WaClient} client
|
|
10
|
+
*/
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getSock() {
|
|
16
|
+
if (!this.client.sock) {
|
|
17
|
+
throw new Error('Socket is not connected.')
|
|
18
|
+
}
|
|
19
|
+
return this.client.sock
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Cria uma nova comunidade (grupo pai de avisos)
|
|
24
|
+
* @param {string} subject - Nome da comunidade
|
|
25
|
+
* @param {string} [description=''] - Descrição da comunidade
|
|
26
|
+
*/
|
|
27
|
+
async create(subject, description = '') {
|
|
28
|
+
const sock = this._getSock()
|
|
29
|
+
if (!sock.communityCreate) {
|
|
30
|
+
throw new Error('communityCreate indisponível no socket.')
|
|
31
|
+
}
|
|
32
|
+
return sock.communityCreate(subject, description)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Obtém metadados da comunidade
|
|
37
|
+
* @param {string} communityJid
|
|
38
|
+
*/
|
|
39
|
+
async getMetadata(communityJid) {
|
|
40
|
+
const sock = this._getSock()
|
|
41
|
+
const targetJid = JidNormalizer.toJid(communityJid)
|
|
42
|
+
if (!sock.communityMetadata) {
|
|
43
|
+
throw new Error('communityMetadata indisponível no socket.')
|
|
44
|
+
}
|
|
45
|
+
return sock.communityMetadata(targetJid)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cria um novo subgrupo já vinculado à comunidade
|
|
50
|
+
* @param {string} communityJid
|
|
51
|
+
* @param {string} subject - Nome do subgrupo
|
|
52
|
+
* @param {string[]} [participants=[]]
|
|
53
|
+
*/
|
|
54
|
+
async createSubgroup(communityJid, subject, participants = []) {
|
|
55
|
+
const sock = this._getSock()
|
|
56
|
+
const targetJid = JidNormalizer.toJid(communityJid)
|
|
57
|
+
const jids = participants.map(JidNormalizer.toJid)
|
|
58
|
+
if (!sock.communityCreateGroup) {
|
|
59
|
+
throw new Error('communityCreateGroup indisponível no socket.')
|
|
60
|
+
}
|
|
61
|
+
return sock.communityCreateGroup(subject, jids, targetJid)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Vincula um grupo existente à comunidade
|
|
66
|
+
* @param {string} communityJid
|
|
67
|
+
* @param {string} groupJid
|
|
68
|
+
*/
|
|
69
|
+
async linkSubgroup(communityJid, groupJid) {
|
|
70
|
+
const sock = this._getSock()
|
|
71
|
+
const parentJid = JidNormalizer.toJid(communityJid)
|
|
72
|
+
const childJid = JidNormalizer.toJid(groupJid)
|
|
73
|
+
if (!sock.communityLinkGroup) {
|
|
74
|
+
throw new Error('communityLinkGroup indisponível no socket.')
|
|
75
|
+
}
|
|
76
|
+
return sock.communityLinkGroup(childJid, parentJid)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Desvincula um subgrupo da comunidade
|
|
81
|
+
* @param {string} communityJid
|
|
82
|
+
* @param {string} groupJid
|
|
83
|
+
*/
|
|
84
|
+
async unlinkSubgroup(communityJid, groupJid) {
|
|
85
|
+
const sock = this._getSock()
|
|
86
|
+
const parentJid = JidNormalizer.toJid(communityJid)
|
|
87
|
+
const childJid = JidNormalizer.toJid(groupJid)
|
|
88
|
+
if (!sock.communityUnlinkGroup) {
|
|
89
|
+
throw new Error('communityUnlinkGroup indisponível no socket.')
|
|
90
|
+
}
|
|
91
|
+
return sock.communityUnlinkGroup(childJid, parentJid)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Retorna a lista de subgrupos vinculados à comunidade
|
|
96
|
+
* @param {string} communityJid
|
|
97
|
+
*/
|
|
98
|
+
async getSubgroups(communityJid) {
|
|
99
|
+
const sock = this._getSock()
|
|
100
|
+
const targetJid = JidNormalizer.toJid(communityJid)
|
|
101
|
+
if (!sock.communityFetchLinkedGroups) {
|
|
102
|
+
throw new Error('communityFetchLinkedGroups indisponível no socket.')
|
|
103
|
+
}
|
|
104
|
+
return sock.communityFetchLinkedGroups(targetJid)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sai da comunidade
|
|
109
|
+
* @param {string} communityJid
|
|
110
|
+
*/
|
|
111
|
+
async leave(communityJid) {
|
|
112
|
+
const sock = this._getSock()
|
|
113
|
+
const targetJid = JidNormalizer.toJid(communityJid)
|
|
114
|
+
if (!sock.communityLeave) {
|
|
115
|
+
throw new Error('communityLeave indisponível no socket.')
|
|
116
|
+
}
|
|
117
|
+
return sock.communityLeave(targetJid)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Altera o nome da comunidade
|
|
122
|
+
* @param {string} communityJid
|
|
123
|
+
* @param {string} subject
|
|
124
|
+
*/
|
|
125
|
+
async setName(communityJid, subject) {
|
|
126
|
+
const sock = this._getSock()
|
|
127
|
+
const targetJid = JidNormalizer.toJid(communityJid)
|
|
128
|
+
if (!sock.communityUpdateSubject) {
|
|
129
|
+
throw new Error('communityUpdateSubject indisponível no socket.')
|
|
130
|
+
}
|
|
131
|
+
return sock.communityUpdateSubject(targetJid, subject)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.CommunityManager = CommunityManager
|
|
136
|
+
exports.default = CommunityManager
|