@kangwifi-pro/waliwa 1.0.2 → 1.1.0
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/dist/community/audio-transcription.d.ts +46 -0
- package/dist/community/audio-transcription.d.ts.map +1 -0
- package/dist/community/audio-transcription.js +108 -0
- package/dist/community/audio-transcription.js.map +1 -0
- package/dist/community/bulk-operations.d.ts +87 -0
- package/dist/community/bulk-operations.d.ts.map +1 -0
- package/dist/community/bulk-operations.js +223 -0
- package/dist/community/bulk-operations.js.map +1 -0
- package/dist/community/community-fixes.d.ts +306 -0
- package/dist/community/community-fixes.d.ts.map +1 -0
- package/dist/community/community-fixes.js +630 -0
- package/dist/community/community-fixes.js.map +1 -0
- package/dist/community/contacts-manager.d.ts +89 -0
- package/dist/community/contacts-manager.d.ts.map +1 -0
- package/dist/community/contacts-manager.js +241 -0
- package/dist/community/contacts-manager.js.map +1 -0
- package/dist/community/disappearing.d.ts +63 -0
- package/dist/community/disappearing.d.ts.map +1 -0
- package/dist/community/disappearing.js +195 -0
- package/dist/community/disappearing.js.map +1 -0
- package/dist/community/index.d.ts +101 -0
- package/dist/community/index.d.ts.map +1 -0
- package/dist/community/index.js +113 -0
- package/dist/community/index.js.map +1 -0
- package/dist/community/live-location.d.ts +85 -0
- package/dist/community/live-location.d.ts.map +1 -0
- package/dist/community/live-location.js +238 -0
- package/dist/community/live-location.js.map +1 -0
- package/dist/community/message-extras.d.ts +110 -0
- package/dist/community/message-extras.d.ts.map +1 -0
- package/dist/community/message-extras.js +472 -0
- package/dist/community/message-extras.js.map +1 -0
- package/dist/community/newsletter-extended.d.ts +142 -0
- package/dist/community/newsletter-extended.d.ts.map +1 -0
- package/dist/community/newsletter-extended.js +543 -0
- package/dist/community/newsletter-extended.js.map +1 -0
- package/dist/community/privacy-manager.d.ts +98 -0
- package/dist/community/privacy-manager.d.ts.map +1 -0
- package/dist/community/privacy-manager.js +273 -0
- package/dist/community/privacy-manager.js.map +1 -0
- package/dist/community/profile-manager.d.ts +94 -0
- package/dist/community/profile-manager.d.ts.map +1 -0
- package/dist/community/profile-manager.js +363 -0
- package/dist/community/profile-manager.js.map +1 -0
- package/dist/community/status-extended.d.ts +119 -0
- package/dist/community/status-extended.d.ts.map +1 -0
- package/dist/community/status-extended.js +444 -0
- package/dist/community/status-extended.js.map +1 -0
- package/dist/community/sticker-manager.d.ts +73 -0
- package/dist/community/sticker-manager.d.ts.map +1 -0
- package/dist/community/sticker-manager.js +251 -0
- package/dist/community/sticker-manager.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/dist/socket/wa-socket.d.ts +77 -0
- package/dist/socket/wa-socket.d.ts.map +1 -1
- package/dist/socket/wa-socket.js +149 -3
- package/dist/socket/wa-socket.js.map +1 -1
- package/package.json +2 -2
- package/src/community/audio-transcription.ts +121 -0
- package/src/community/bulk-operations.ts +329 -0
- package/src/community/community-fixes.ts +771 -0
- package/src/community/contacts-manager.ts +282 -0
- package/src/community/disappearing.ts +218 -0
- package/src/community/index.ts +169 -0
- package/src/community/live-location.ts +287 -0
- package/src/community/message-extras.ts +523 -0
- package/src/community/newsletter-extended.ts +614 -0
- package/src/community/privacy-manager.ts +310 -0
- package/src/community/profile-manager.ts +402 -0
- package/src/community/status-extended.ts +518 -0
- package/src/community/sticker-manager.ts +305 -0
- package/src/index.ts +67 -2
- package/src/socket/wa-socket.ts +183 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waliwa - Newsletter Extended (Community Request)
|
|
3
|
+
*
|
|
4
|
+
* Fitur yang sering diminta komunitas Baileys untuk Newsletter/Channel:
|
|
5
|
+
* - Subscribe/unsubscribe newsletter
|
|
6
|
+
* - Mute/unmute newsletter
|
|
7
|
+
* - Get newsletter metadata (subscriber count, verification, etc)
|
|
8
|
+
* - Post to newsletter (text/media)
|
|
9
|
+
* - Get newsletter posts
|
|
10
|
+
* - Newsletter admin operations (mute users, etc)
|
|
11
|
+
* - Newsletter verification
|
|
12
|
+
* - Newsletter ownership transfer
|
|
13
|
+
*
|
|
14
|
+
* Fix Baileys issues:
|
|
15
|
+
* - Newsletter support sangat terbatas
|
|
16
|
+
* - Newsletter mentions tidak support
|
|
17
|
+
* - Newsletter mute tidak ada
|
|
18
|
+
* - Newsletter subscriber count tidak bisa di-get
|
|
19
|
+
*/
|
|
20
|
+
import type { JIDLike, WALogger, MessageType } from '../types/index.js';
|
|
21
|
+
import { BinaryNode } from '../core/binary.js';
|
|
22
|
+
export interface NewsletterMetadata {
|
|
23
|
+
id: JIDLike;
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
subscribersCount: number;
|
|
27
|
+
state: 'active' | 'inactive';
|
|
28
|
+
createdAt?: number;
|
|
29
|
+
verification: 'verified' | 'unverified';
|
|
30
|
+
isOwner: boolean;
|
|
31
|
+
isAdmin: boolean;
|
|
32
|
+
isMuted: boolean;
|
|
33
|
+
pictureUrl?: string;
|
|
34
|
+
role?: 'owner' | 'admin' | 'member' | 'subscriber';
|
|
35
|
+
}
|
|
36
|
+
export interface NewsletterPost {
|
|
37
|
+
id: string;
|
|
38
|
+
newsletterId: JIDLike;
|
|
39
|
+
author: string;
|
|
40
|
+
type: MessageType;
|
|
41
|
+
text?: string;
|
|
42
|
+
mediaUrl?: string;
|
|
43
|
+
timestamp: number;
|
|
44
|
+
reactions?: Array<{
|
|
45
|
+
emoji: string;
|
|
46
|
+
count: number;
|
|
47
|
+
}>;
|
|
48
|
+
repliesCount: number;
|
|
49
|
+
}
|
|
50
|
+
export interface NewsletterManagerOptions {
|
|
51
|
+
send: (data: Uint8Array) => void;
|
|
52
|
+
registerIqHandler: (id: string, handler: (node: BinaryNode) => void) => void;
|
|
53
|
+
logger?: WALogger;
|
|
54
|
+
}
|
|
55
|
+
export declare class NewsletterManager {
|
|
56
|
+
private send;
|
|
57
|
+
private registerIqHandler;
|
|
58
|
+
private logger;
|
|
59
|
+
private metadataCache;
|
|
60
|
+
private readonly cacheTtlMs;
|
|
61
|
+
constructor(opts: NewsletterManagerOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Create new newsletter
|
|
64
|
+
*/
|
|
65
|
+
create(name: string, description?: string): Promise<NewsletterMetadata>;
|
|
66
|
+
/**
|
|
67
|
+
* Subscribe ke newsletter
|
|
68
|
+
*/
|
|
69
|
+
subscribe(newsletterId: JIDLike): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Unsubscribe dari newsletter
|
|
72
|
+
*/
|
|
73
|
+
unsubscribe(newsletterId: JIDLike): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Mute newsletter (stop notifications)
|
|
76
|
+
* Fix Baileys issue: newsletter mute tidak ada
|
|
77
|
+
*/
|
|
78
|
+
mute(newsletterId: JIDLike): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Unmute newsletter
|
|
81
|
+
*/
|
|
82
|
+
unmute(newsletterId: JIDLike): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Get newsletter metadata (subscriber count, verification, dll)
|
|
85
|
+
* Fix Baileys issue: subscriber count tidak bisa di-get
|
|
86
|
+
*/
|
|
87
|
+
getMetadata(newsletterId: JIDLike, useCache?: boolean): Promise<NewsletterMetadata>;
|
|
88
|
+
/**
|
|
89
|
+
* Post text to newsletter
|
|
90
|
+
*/
|
|
91
|
+
postText(newsletterId: JIDLike, text: string): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Post media to newsletter
|
|
94
|
+
*/
|
|
95
|
+
postMedia(newsletterId: JIDLike, mediaType: 'image' | 'video' | 'audio' | 'document', mediaUrl: string, caption?: string): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* React to newsletter post
|
|
98
|
+
*/
|
|
99
|
+
reactToPost(newsletterId: JIDLike, postId: string, emoji: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Get posts dari newsletter
|
|
102
|
+
*/
|
|
103
|
+
getPosts(newsletterId: JIDLike, limit?: number, before?: string): Promise<NewsletterPost[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Delete newsletter post (admin only)
|
|
106
|
+
*/
|
|
107
|
+
deletePost(newsletterId: JIDLike, postId: string): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Update newsletter info (admin only)
|
|
110
|
+
*/
|
|
111
|
+
updateInfo(newsletterId: JIDLike, updates: {
|
|
112
|
+
name?: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Mute user di newsletter (admin only)
|
|
117
|
+
*/
|
|
118
|
+
muteUser(newsletterId: JIDLike, userJid: JIDLike, durationMs: number): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Verify newsletter (admin only, requires verified account)
|
|
121
|
+
*/
|
|
122
|
+
verify(newsletterId: JIDLike): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Transfer newsletter ownership (admin only)
|
|
125
|
+
*/
|
|
126
|
+
transferOwnership(newsletterId: JIDLike, newOwnerJid: JIDLike): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Delete newsletter (owner only)
|
|
129
|
+
*/
|
|
130
|
+
delete(newsletterId: JIDLike): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Get subscriber list (admin only)
|
|
133
|
+
*/
|
|
134
|
+
getSubscribers(newsletterId: JIDLike, limit?: number): Promise<string[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Clear metadata cache
|
|
137
|
+
*/
|
|
138
|
+
clearCache(): void;
|
|
139
|
+
private findChild;
|
|
140
|
+
private sendIqAndWait;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=newsletter-extended.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newsletter-extended.d.ts","sourceRoot":"","sources":["../../src/community/newsletter-extended.ts"],"names":[],"mappings":"AAAA;;;;;;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unsubscribe newsletter
|
|
7
|
+
* - Mute/unmute newsletter
|
|
8
|
+
* - Get newsletter metadata (subscriber count, verification, etc)
|
|
9
|
+
* - Post to newsletter (text/media)
|
|
10
|
+
* - Get newsletter posts
|
|
11
|
+
* - Newsletter admin operations (mute users, etc)
|
|
12
|
+
* - Newsletter verification
|
|
13
|
+
* - Newsletter ownership transfer
|
|
14
|
+
*
|
|
15
|
+
* Fix Baileys issues:
|
|
16
|
+
* - Newsletter support sangat terbatas
|
|
17
|
+
* - Newsletter mentions tidak support
|
|
18
|
+
* - Newsletter mute tidak ada
|
|
19
|
+
* - Newsletter subscriber count tidak bisa di-get
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.NewsletterManager = void 0;
|
|
23
|
+
const binary_js_1 = require("../core/binary.js");
|
|
24
|
+
const jid_js_1 = require("../utils/jid.js");
|
|
25
|
+
const message_encoder_js_1 = require("../messages/message-encoder.js");
|
|
26
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
27
|
+
class NewsletterManager {
|
|
28
|
+
send;
|
|
29
|
+
registerIqHandler;
|
|
30
|
+
logger;
|
|
31
|
+
metadataCache = new Map();
|
|
32
|
+
cacheTtlMs = 60 * 1000;
|
|
33
|
+
constructor(opts) {
|
|
34
|
+
this.send = opts.send;
|
|
35
|
+
this.registerIqHandler = opts.registerIqHandler;
|
|
36
|
+
this.logger = opts.logger ?? new logger_js_1.SilentLogger();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create new newsletter
|
|
40
|
+
*/
|
|
41
|
+
async create(name, description) {
|
|
42
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
43
|
+
const node = {
|
|
44
|
+
tag: 'iq',
|
|
45
|
+
attrs: {
|
|
46
|
+
type: 'set',
|
|
47
|
+
to: 's.whatsapp.net',
|
|
48
|
+
id
|
|
49
|
+
},
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
tag: 'newsletter',
|
|
53
|
+
attrs: {
|
|
54
|
+
name,
|
|
55
|
+
description: description ?? ''
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
};
|
|
60
|
+
const response = await this.sendIqAndWait(node, id);
|
|
61
|
+
const nlNode = this.findChild(response, 'newsletter');
|
|
62
|
+
return {
|
|
63
|
+
id: nlNode?.attrs?.id ?? '',
|
|
64
|
+
name,
|
|
65
|
+
description,
|
|
66
|
+
subscribersCount: 1,
|
|
67
|
+
state: 'active',
|
|
68
|
+
verification: 'unverified',
|
|
69
|
+
isOwner: true,
|
|
70
|
+
isAdmin: true,
|
|
71
|
+
isMuted: false
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe ke newsletter
|
|
76
|
+
*/
|
|
77
|
+
async subscribe(newsletterId) {
|
|
78
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
79
|
+
const node = {
|
|
80
|
+
tag: 'iq',
|
|
81
|
+
attrs: {
|
|
82
|
+
type: 'set',
|
|
83
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
84
|
+
id
|
|
85
|
+
},
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
tag: 'subscribe',
|
|
89
|
+
attrs: { action: 'subscribe' }
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
await this.sendIqAndWait(node, id);
|
|
94
|
+
this.logger.info(`Subscribed to newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Unsubscribe dari newsletter
|
|
98
|
+
*/
|
|
99
|
+
async unsubscribe(newsletterId) {
|
|
100
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
101
|
+
const node = {
|
|
102
|
+
tag: 'iq',
|
|
103
|
+
attrs: {
|
|
104
|
+
type: 'set',
|
|
105
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
106
|
+
id
|
|
107
|
+
},
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
tag: 'subscribe',
|
|
111
|
+
attrs: { action: 'unsubscribe' }
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
};
|
|
115
|
+
await this.sendIqAndWait(node, id);
|
|
116
|
+
this.logger.info(`Unsubscribed from newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Mute newsletter (stop notifications)
|
|
120
|
+
* Fix Baileys issue: newsletter mute tidak ada
|
|
121
|
+
*/
|
|
122
|
+
async mute(newsletterId) {
|
|
123
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
124
|
+
const node = {
|
|
125
|
+
tag: 'iq',
|
|
126
|
+
attrs: {
|
|
127
|
+
type: 'set',
|
|
128
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
129
|
+
id
|
|
130
|
+
},
|
|
131
|
+
content: [
|
|
132
|
+
{
|
|
133
|
+
tag: 'mute',
|
|
134
|
+
attrs: { action: 'mute' }
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
};
|
|
138
|
+
await this.sendIqAndWait(node, id);
|
|
139
|
+
this.logger.info(`Muted newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Unmute newsletter
|
|
143
|
+
*/
|
|
144
|
+
async unmute(newsletterId) {
|
|
145
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
146
|
+
const node = {
|
|
147
|
+
tag: 'iq',
|
|
148
|
+
attrs: {
|
|
149
|
+
type: 'set',
|
|
150
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
151
|
+
id
|
|
152
|
+
},
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
tag: 'mute',
|
|
156
|
+
attrs: { action: 'unmute' }
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
await this.sendIqAndWait(node, id);
|
|
161
|
+
this.logger.info(`Unmuted newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get newsletter metadata (subscriber count, verification, dll)
|
|
165
|
+
* Fix Baileys issue: subscriber count tidak bisa di-get
|
|
166
|
+
*/
|
|
167
|
+
async getMetadata(newsletterId, useCache = true) {
|
|
168
|
+
const jidStr = (0, jid_js_1.jidToString)(newsletterId);
|
|
169
|
+
if (useCache) {
|
|
170
|
+
const cached = this.metadataCache.get(jidStr);
|
|
171
|
+
if (cached && Date.now() - cached.cachedAt < this.cacheTtlMs) {
|
|
172
|
+
return cached.meta;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
176
|
+
const node = {
|
|
177
|
+
tag: 'iq',
|
|
178
|
+
attrs: {
|
|
179
|
+
type: 'get',
|
|
180
|
+
to: jidStr,
|
|
181
|
+
id
|
|
182
|
+
},
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
tag: 'newsletter_metadata',
|
|
186
|
+
attrs: {}
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
};
|
|
190
|
+
const response = await this.sendIqAndWait(node, id);
|
|
191
|
+
const metaNode = this.findChild(response, 'newsletter_metadata');
|
|
192
|
+
const meta = {
|
|
193
|
+
id: jidStr,
|
|
194
|
+
name: metaNode?.attrs?.name ?? '',
|
|
195
|
+
description: metaNode?.attrs?.description,
|
|
196
|
+
subscribersCount: parseInt(metaNode?.attrs?.subscribers_count ?? '0', 10),
|
|
197
|
+
state: metaNode?.attrs?.state ?? 'active',
|
|
198
|
+
createdAt: metaNode?.attrs?.created_at ? parseInt(metaNode.attrs.created_at, 10) : undefined,
|
|
199
|
+
verification: metaNode?.attrs?.verification === 'verified' ? 'verified' : 'unverified',
|
|
200
|
+
isOwner: metaNode?.attrs?.is_owner === 'true',
|
|
201
|
+
isAdmin: metaNode?.attrs?.is_admin === 'true',
|
|
202
|
+
isMuted: metaNode?.attrs?.is_muted === 'true',
|
|
203
|
+
pictureUrl: metaNode?.attrs?.picture_url,
|
|
204
|
+
role: metaNode?.attrs?.role
|
|
205
|
+
};
|
|
206
|
+
this.metadataCache.set(jidStr, { meta, cachedAt: Date.now() });
|
|
207
|
+
return meta;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Post text to newsletter
|
|
211
|
+
*/
|
|
212
|
+
async postText(newsletterId, text) {
|
|
213
|
+
const messageId = (0, message_encoder_js_1.generateMessageId)();
|
|
214
|
+
const node = {
|
|
215
|
+
tag: 'message',
|
|
216
|
+
attrs: {
|
|
217
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
218
|
+
type: 'text',
|
|
219
|
+
id: messageId
|
|
220
|
+
},
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
tag: 'newsletter_text',
|
|
224
|
+
attrs: {},
|
|
225
|
+
content: text
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
};
|
|
229
|
+
this.send((0, binary_js_1.encodeBinaryNode)(node));
|
|
230
|
+
this.logger.info(`Posted text to newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
231
|
+
return messageId;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Post media to newsletter
|
|
235
|
+
*/
|
|
236
|
+
async postMedia(newsletterId, mediaType, mediaUrl, caption) {
|
|
237
|
+
const messageId = (0, message_encoder_js_1.generateMessageId)();
|
|
238
|
+
const tag = `newsletter_${mediaType}`;
|
|
239
|
+
const node = {
|
|
240
|
+
tag: 'message',
|
|
241
|
+
attrs: {
|
|
242
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
243
|
+
type: mediaType,
|
|
244
|
+
id: messageId
|
|
245
|
+
},
|
|
246
|
+
content: [
|
|
247
|
+
{
|
|
248
|
+
tag,
|
|
249
|
+
attrs: {
|
|
250
|
+
url: mediaUrl,
|
|
251
|
+
caption: caption ?? ''
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
};
|
|
256
|
+
this.send((0, binary_js_1.encodeBinaryNode)(node));
|
|
257
|
+
this.logger.info(`Posted ${mediaType} to newsletter ${(0, jid_js_1.jidToString)(newsletterId)}`);
|
|
258
|
+
return messageId;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* React to newsletter post
|
|
262
|
+
*/
|
|
263
|
+
async reactToPost(newsletterId, postId, emoji) {
|
|
264
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
265
|
+
const node = {
|
|
266
|
+
tag: 'iq',
|
|
267
|
+
attrs: {
|
|
268
|
+
type: 'set',
|
|
269
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
270
|
+
id
|
|
271
|
+
},
|
|
272
|
+
content: [
|
|
273
|
+
{
|
|
274
|
+
tag: 'newsletter_reaction',
|
|
275
|
+
attrs: {
|
|
276
|
+
post_id: postId,
|
|
277
|
+
emoji
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
};
|
|
282
|
+
await this.sendIqAndWait(node, id);
|
|
283
|
+
this.logger.debug(`Reacted ${emoji} to post ${postId}`);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get posts dari newsletter
|
|
287
|
+
*/
|
|
288
|
+
async getPosts(newsletterId, limit = 20, before) {
|
|
289
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
290
|
+
const node = {
|
|
291
|
+
tag: 'iq',
|
|
292
|
+
attrs: {
|
|
293
|
+
type: 'get',
|
|
294
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
295
|
+
id
|
|
296
|
+
},
|
|
297
|
+
content: [
|
|
298
|
+
{
|
|
299
|
+
tag: 'newsletter_posts',
|
|
300
|
+
attrs: {
|
|
301
|
+
limit: limit.toString(),
|
|
302
|
+
...(before ? { before } : {})
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
};
|
|
307
|
+
const response = await this.sendIqAndWait(node, id);
|
|
308
|
+
const postsNode = this.findChild(response, 'newsletter_posts');
|
|
309
|
+
const posts = [];
|
|
310
|
+
if (Array.isArray(postsNode?.content)) {
|
|
311
|
+
for (const child of postsNode.content) {
|
|
312
|
+
if (typeof child !== 'object' || child?.tag !== 'post')
|
|
313
|
+
continue;
|
|
314
|
+
posts.push({
|
|
315
|
+
id: child.attrs?.id ?? '',
|
|
316
|
+
newsletterId,
|
|
317
|
+
author: child.attrs?.author ?? '',
|
|
318
|
+
type: child.attrs?.type ?? 'text',
|
|
319
|
+
text: typeof child.content === 'string' ? child.content : undefined,
|
|
320
|
+
mediaUrl: child.attrs?.url,
|
|
321
|
+
timestamp: parseInt(child.attrs?.timestamp ?? '0', 10),
|
|
322
|
+
repliesCount: parseInt(child.attrs?.replies_count ?? '0', 10)
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return posts;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Delete newsletter post (admin only)
|
|
330
|
+
*/
|
|
331
|
+
async deletePost(newsletterId, postId) {
|
|
332
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
333
|
+
const node = {
|
|
334
|
+
tag: 'iq',
|
|
335
|
+
attrs: {
|
|
336
|
+
type: 'set',
|
|
337
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
338
|
+
id
|
|
339
|
+
},
|
|
340
|
+
content: [
|
|
341
|
+
{
|
|
342
|
+
tag: 'newsletter_post_delete',
|
|
343
|
+
attrs: { post_id: postId }
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
};
|
|
347
|
+
await this.sendIqAndWait(node, id);
|
|
348
|
+
this.logger.info(`Deleted post ${postId} from newsletter`);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Update newsletter info (admin only)
|
|
352
|
+
*/
|
|
353
|
+
async updateInfo(newsletterId, updates) {
|
|
354
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
355
|
+
const content = [];
|
|
356
|
+
if (updates.name) {
|
|
357
|
+
content.push({ tag: 'name', attrs: {}, content: updates.name });
|
|
358
|
+
}
|
|
359
|
+
if (updates.description !== undefined) {
|
|
360
|
+
content.push({ tag: 'description', attrs: {}, content: updates.description });
|
|
361
|
+
}
|
|
362
|
+
const node = {
|
|
363
|
+
tag: 'iq',
|
|
364
|
+
attrs: {
|
|
365
|
+
type: 'set',
|
|
366
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
367
|
+
id
|
|
368
|
+
},
|
|
369
|
+
content: [
|
|
370
|
+
{
|
|
371
|
+
tag: 'newsletter_update',
|
|
372
|
+
attrs: {},
|
|
373
|
+
content
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
};
|
|
377
|
+
await this.sendIqAndWait(node, id);
|
|
378
|
+
this.metadataCache.delete((0, jid_js_1.jidToString)(newsletterId));
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Mute user di newsletter (admin only)
|
|
382
|
+
*/
|
|
383
|
+
async muteUser(newsletterId, userJid, durationMs) {
|
|
384
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
385
|
+
const node = {
|
|
386
|
+
tag: 'iq',
|
|
387
|
+
attrs: {
|
|
388
|
+
type: 'set',
|
|
389
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
390
|
+
id
|
|
391
|
+
},
|
|
392
|
+
content: [
|
|
393
|
+
{
|
|
394
|
+
tag: 'newsletter_user_mute',
|
|
395
|
+
attrs: {
|
|
396
|
+
user_jid: (0, jid_js_1.jidToString)(userJid),
|
|
397
|
+
duration: Math.floor(durationMs / 1000).toString()
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
]
|
|
401
|
+
};
|
|
402
|
+
await this.sendIqAndWait(node, id);
|
|
403
|
+
this.logger.info(`Muted user ${(0, jid_js_1.jidToString)(userJid)} in newsletter for ${durationMs}ms`);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Verify newsletter (admin only, requires verified account)
|
|
407
|
+
*/
|
|
408
|
+
async verify(newsletterId) {
|
|
409
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
410
|
+
const node = {
|
|
411
|
+
tag: 'iq',
|
|
412
|
+
attrs: {
|
|
413
|
+
type: 'set',
|
|
414
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
415
|
+
id
|
|
416
|
+
},
|
|
417
|
+
content: [
|
|
418
|
+
{
|
|
419
|
+
tag: 'newsletter_verify',
|
|
420
|
+
attrs: { action: 'verify' }
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
};
|
|
424
|
+
await this.sendIqAndWait(node, id);
|
|
425
|
+
this.logger.info(`Newsletter ${(0, jid_js_1.jidToString)(newsletterId)} verified`);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Transfer newsletter ownership (admin only)
|
|
429
|
+
*/
|
|
430
|
+
async transferOwnership(newsletterId, newOwnerJid) {
|
|
431
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
432
|
+
const node = {
|
|
433
|
+
tag: 'iq',
|
|
434
|
+
attrs: {
|
|
435
|
+
type: 'set',
|
|
436
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
437
|
+
id
|
|
438
|
+
},
|
|
439
|
+
content: [
|
|
440
|
+
{
|
|
441
|
+
tag: 'newsletter_ownership_transfer',
|
|
442
|
+
attrs: { new_owner: (0, jid_js_1.jidToString)(newOwnerJid) }
|
|
443
|
+
}
|
|
444
|
+
]
|
|
445
|
+
};
|
|
446
|
+
await this.sendIqAndWait(node, id);
|
|
447
|
+
this.logger.info(`Newsletter ownership transferred to ${(0, jid_js_1.jidToString)(newOwnerJid)}`);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Delete newsletter (owner only)
|
|
451
|
+
*/
|
|
452
|
+
async delete(newsletterId) {
|
|
453
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
454
|
+
const node = {
|
|
455
|
+
tag: 'iq',
|
|
456
|
+
attrs: {
|
|
457
|
+
type: 'set',
|
|
458
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
459
|
+
id
|
|
460
|
+
},
|
|
461
|
+
content: [
|
|
462
|
+
{
|
|
463
|
+
tag: 'newsletter_delete',
|
|
464
|
+
attrs: {}
|
|
465
|
+
}
|
|
466
|
+
]
|
|
467
|
+
};
|
|
468
|
+
await this.sendIqAndWait(node, id);
|
|
469
|
+
this.metadataCache.delete((0, jid_js_1.jidToString)(newsletterId));
|
|
470
|
+
this.logger.info(`Newsletter ${(0, jid_js_1.jidToString)(newsletterId)} deleted`);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Get subscriber list (admin only)
|
|
474
|
+
*/
|
|
475
|
+
async getSubscribers(newsletterId, limit = 100) {
|
|
476
|
+
const id = (0, message_encoder_js_1.generateStanzaId)();
|
|
477
|
+
const node = {
|
|
478
|
+
tag: 'iq',
|
|
479
|
+
attrs: {
|
|
480
|
+
type: 'get',
|
|
481
|
+
to: (0, jid_js_1.jidToString)(newsletterId),
|
|
482
|
+
id
|
|
483
|
+
},
|
|
484
|
+
content: [
|
|
485
|
+
{
|
|
486
|
+
tag: 'newsletter_subscribers',
|
|
487
|
+
attrs: { limit: limit.toString() }
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
};
|
|
491
|
+
const response = await this.sendIqAndWait(node, id);
|
|
492
|
+
const subsNode = this.findChild(response, 'newsletter_subscribers');
|
|
493
|
+
const subscribers = [];
|
|
494
|
+
if (Array.isArray(subsNode?.content)) {
|
|
495
|
+
for (const child of subsNode.content) {
|
|
496
|
+
if (typeof child === 'object' && child?.tag === 'subscriber' && child.attrs?.jid) {
|
|
497
|
+
subscribers.push(child.attrs.jid);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return subscribers;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Clear metadata cache
|
|
505
|
+
*/
|
|
506
|
+
clearCache() {
|
|
507
|
+
this.metadataCache.clear();
|
|
508
|
+
}
|
|
509
|
+
// ============== Helpers ==============
|
|
510
|
+
findChild(node, tag) {
|
|
511
|
+
if (!Array.isArray(node.content))
|
|
512
|
+
return null;
|
|
513
|
+
for (const child of node.content) {
|
|
514
|
+
if (typeof child === 'object' && child?.tag === tag)
|
|
515
|
+
return child;
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
sendIqAndWait(node, id, timeoutMs = 15000) {
|
|
520
|
+
return new Promise((resolve, reject) => {
|
|
521
|
+
const timeout = setTimeout(() => reject(new Error(`IQ ${id} timeout`)), timeoutMs);
|
|
522
|
+
this.registerIqHandler(id, (response) => {
|
|
523
|
+
clearTimeout(timeout);
|
|
524
|
+
const type = response.attrs?.type;
|
|
525
|
+
if (type === 'error') {
|
|
526
|
+
reject(new Error(`IQ error: ${JSON.stringify(response.attrs)}`));
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
resolve(response);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
try {
|
|
533
|
+
this.send((0, binary_js_1.encodeBinaryNode)(node));
|
|
534
|
+
}
|
|
535
|
+
catch (err) {
|
|
536
|
+
clearTimeout(timeout);
|
|
537
|
+
reject(err);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
exports.NewsletterManager = NewsletterManager;
|
|
543
|
+
//# sourceMappingURL=newsletter-extended.js.map
|