@theophilusdev/conduit 1.0.2 → 1.1.3

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 CHANGED
@@ -25,8 +25,9 @@ npm install @theophilusdev/conduit
25
25
 
26
26
  ```ts
27
27
  import { ConduitClient } from "@theophilusdev/conduit";
28
- import appstate from "./appstate.json" assert { type: "json" };
28
+ import fs from "fs";
29
29
 
30
+ const appstate = fs.readFileSync("./appstate.json", "utf-8");
30
31
  const client = new ConduitClient({ listenEvents: true });
31
32
 
32
33
  await client.login({ appstate });
@@ -72,12 +73,14 @@ Handlers receive a context object and an optional `next()` function for middlewa
72
73
 
73
74
  All events include:
74
75
 
75
- - `send(body)`
76
+ - `send(body)` — send a message to the same thread
76
77
 
77
78
  Message events additionally include:
78
79
 
79
- - `reply(body)`
80
- - `react(emoji)`
80
+ - `reply(body)` — quoted reply to the triggering message
81
+ - `react(emoji)` — react to the triggering message
82
+
83
+ Both `send()` and `reply()` accept a plain string or a `ConduitMessageBody` object for rich messages with attachments and mentions.
81
84
 
82
85
  ### Message Events
83
86
 
package/dist/index.cjs CHANGED
@@ -60,7 +60,24 @@ var ConduitMessagesAPI = class {
60
60
  * @param threadID - The target thread ID.
61
61
  */
62
62
  send(body, threadID) {
63
- return this.bot.ctx.api.sendMessage({ body }, threadID);
63
+ if (typeof body === "string") {
64
+ return new Promise((resolve, reject) => {
65
+ this.bot.ctx.api.sendMessage(
66
+ { body },
67
+ threadID,
68
+ (err, data) => {
69
+ if (err) reject(err);
70
+ else resolve(data);
71
+ }
72
+ );
73
+ });
74
+ }
75
+ return new Promise((resolve, reject) => {
76
+ this.bot.ctx.api.sendMessage(body, threadID, (err, data) => {
77
+ if (err) reject(err);
78
+ else resolve(data);
79
+ });
80
+ });
64
81
  }
65
82
  /**
66
83
  * Sends a quoted reply to a specific message.
@@ -69,12 +86,30 @@ var ConduitMessagesAPI = class {
69
86
  * @param messageID - The message ID to reply to.
70
87
  */
71
88
  reply(body, threadID, messageID) {
72
- return this.bot.ctx.api.sendMessage(
73
- { body },
74
- threadID,
75
- void 0,
76
- messageID
77
- );
89
+ if (typeof body === "string") {
90
+ return new Promise((resolve, reject) => {
91
+ this.bot.ctx.api.sendMessage(
92
+ { body },
93
+ threadID,
94
+ (err, data) => {
95
+ if (err) reject(err);
96
+ else resolve(data);
97
+ },
98
+ messageID
99
+ );
100
+ });
101
+ }
102
+ return new Promise((resolve, reject) => {
103
+ this.bot.ctx.api.sendMessage(
104
+ body,
105
+ threadID,
106
+ (err, data) => {
107
+ if (err) reject(err);
108
+ else resolve(data);
109
+ },
110
+ messageID
111
+ );
112
+ });
78
113
  }
79
114
  /**
80
115
  * Edits an existing message.
@@ -82,21 +117,36 @@ var ConduitMessagesAPI = class {
82
117
  * @param body - The new message text.
83
118
  */
84
119
  edit(messageID, body) {
85
- return this.bot.ctx.api.editMessage(body, messageID);
120
+ return new Promise((resolve, reject) => {
121
+ this.bot.ctx.api.editMessage(body, messageID, (err, data) => {
122
+ if (err) reject(err);
123
+ else resolve(data);
124
+ });
125
+ });
86
126
  }
87
127
  /**
88
128
  * Unsends (retracts) a message sent by the bot.
89
129
  * @param messageID - The message ID to unsend.
90
130
  */
91
131
  unsend(messageID) {
92
- return this.bot.ctx.api.unsendMessage(messageID);
132
+ return new Promise((resolve, reject) => {
133
+ this.bot.ctx.api.unsendMessage(messageID, (err) => {
134
+ if (err) reject(err);
135
+ else resolve(null);
136
+ });
137
+ });
93
138
  }
94
139
  /**
95
140
  * Deletes a message.
96
141
  * @param messageID - The message ID to delete.
97
142
  */
98
143
  delete(messageID) {
99
- return this.bot.ctx.api.deleteMessage(messageID);
144
+ return new Promise((resolve, reject) => {
145
+ this.bot.ctx.api.deleteMessage(messageID, (err) => {
146
+ if (err) reject(err);
147
+ else resolve(null);
148
+ });
149
+ });
100
150
  }
101
151
  /**
102
152
  * Adds or removes a reaction on a message.
@@ -105,28 +155,53 @@ var ConduitMessagesAPI = class {
105
155
  * @param threadID - The thread the message belongs to.
106
156
  */
107
157
  react(emoji, messageID, threadID) {
108
- return this.bot.ctx.api.setMessageReaction(emoji, messageID, threadID);
158
+ return new Promise((resolve, reject) => {
159
+ this.bot.ctx.api.setMessageReaction(
160
+ emoji,
161
+ messageID,
162
+ (err) => {
163
+ if (err) reject(err);
164
+ else resolve(null);
165
+ },
166
+ threadID
167
+ );
168
+ });
109
169
  }
110
170
  /**
111
171
  * Sends a typing indicator to a thread.
112
172
  * @param threadID - The target thread ID.
113
173
  */
114
174
  sendTypingIndicator(threadID) {
115
- return this.bot.ctx.api.sendTypingIndicator(threadID);
175
+ return new Promise((resolve, reject) => {
176
+ this.bot.ctx.api.sendTypingIndicator(threadID, (err) => {
177
+ if (err) reject(err);
178
+ else resolve(null);
179
+ });
180
+ });
116
181
  }
117
182
  /**
118
183
  * Marks a message as read.
119
184
  * @param messageID - The message ID to mark as read.
120
185
  */
121
186
  markAsRead(messageID) {
122
- return this.bot.ctx.api.markAsRead(messageID);
187
+ return new Promise((resolve, reject) => {
188
+ this.bot.ctx.api.markAsRead(messageID, (err) => {
189
+ if (err) reject(err);
190
+ else resolve(null);
191
+ });
192
+ });
123
193
  }
124
194
  /**
125
195
  * Uploads a file attachment and returns an attachment object.
126
196
  * @param file - A readable stream or file buffer.
127
197
  */
128
198
  uploadAttachment(file) {
129
- return this.bot.ctx.api.uploadAttachment(file);
199
+ return new Promise((resolve, reject) => {
200
+ this.bot.ctx.api.uploadAttachment(file, (err, data) => {
201
+ if (err) reject(err);
202
+ else resolve(data);
203
+ });
204
+ });
130
205
  }
131
206
  /**
132
207
  * Forwards an existing attachment to another thread.
@@ -134,7 +209,12 @@ var ConduitMessagesAPI = class {
134
209
  * @param threadID - The target thread ID.
135
210
  */
136
211
  forwardAttachment(attachmentID, threadID) {
137
- return this.bot.ctx.api.forwardAttachment(attachmentID, threadID);
212
+ return new Promise((resolve, reject) => {
213
+ this.bot.ctx.api.forwardAttachment(attachmentID, threadID, (err) => {
214
+ if (err) reject(err);
215
+ else resolve(null);
216
+ });
217
+ });
138
218
  }
139
219
  /**
140
220
  * Shares a contact card to a thread.
@@ -142,7 +222,12 @@ var ConduitMessagesAPI = class {
142
222
  * @param threadID - The target thread ID.
143
223
  */
144
224
  shareContact(userID, threadID) {
145
- return this.bot.ctx.api.shareContact(userID, threadID);
225
+ return new Promise((resolve, reject) => {
226
+ this.bot.ctx.api.shareContact(userID, threadID, (err, data) => {
227
+ if (err) reject(err);
228
+ else resolve(data);
229
+ });
230
+ });
146
231
  }
147
232
  /**
148
233
  * Changes the color theme of a thread.
@@ -150,7 +235,12 @@ var ConduitMessagesAPI = class {
150
235
  * @param threadID - The target thread ID.
151
236
  */
152
237
  changeThreadColor(color, threadID) {
153
- return this.bot.ctx.api.changeThreadColor(color, threadID);
238
+ return new Promise((resolve, reject) => {
239
+ this.bot.ctx.api.changeThreadColor(color, threadID, (err) => {
240
+ if (err) reject(err);
241
+ else resolve(null);
242
+ });
243
+ });
154
244
  }
155
245
  /**
156
246
  * Changes the quick-reaction emoji of a thread.
@@ -158,20 +248,35 @@ var ConduitMessagesAPI = class {
158
248
  * @param threadID - The target thread ID.
159
249
  */
160
250
  changeThreadEmoji(emoji, threadID) {
161
- return this.bot.ctx.api.changeThreadEmoji(emoji, threadID);
251
+ return new Promise((resolve, reject) => {
252
+ this.bot.ctx.api.changeThreadEmoji(emoji, threadID, (err) => {
253
+ if (err) reject(err);
254
+ else resolve(null);
255
+ });
256
+ });
162
257
  }
163
258
  /**
164
259
  * Fetches a specific message by ID.
165
260
  * @param messageID - The message ID to fetch.
166
261
  */
167
262
  getMessage(messageID) {
168
- return this.bot.ctx.api.getMessage(messageID);
263
+ return new Promise((resolve, reject) => {
264
+ this.bot.ctx.api.getMessage(messageID, (err, data) => {
265
+ if (err) reject(err);
266
+ else resolve(data);
267
+ });
268
+ });
169
269
  }
170
270
  /**
171
271
  * Returns all available thread color themes.
172
272
  */
173
273
  getThreadColors() {
174
- return this.bot.ctx.api.getThreadColors();
274
+ return new Promise((resolve, reject) => {
275
+ this.bot.ctx.api.getThreadColors((err, data) => {
276
+ if (err) reject(err);
277
+ else resolve(data);
278
+ });
279
+ });
175
280
  }
176
281
  };
177
282
 
@@ -186,7 +291,12 @@ var ConduitThreadsAPI = class {
186
291
  * @param threadID - The thread ID to query.
187
292
  */
188
293
  getInfo(threadID) {
189
- return this.bot.ctx.api.getThreadInfo(threadID);
294
+ return new Promise((resolve, reject) => {
295
+ this.bot.ctx.api.getThreadInfo(threadID, (err, data) => {
296
+ if (err) reject(err);
297
+ else resolve(data);
298
+ });
299
+ });
190
300
  }
191
301
  /**
192
302
  * Fetches a paginated list of threads.
@@ -195,7 +305,17 @@ var ConduitThreadsAPI = class {
195
305
  * @param folders - Folder filters e.g. `["INBOX"]`.
196
306
  */
197
307
  getList(limit, cursor, folders) {
198
- return this.bot.ctx.api.getThreadList(limit, cursor, folders);
308
+ return new Promise((resolve, reject) => {
309
+ this.bot.ctx.api.getThreadList(
310
+ limit,
311
+ cursor,
312
+ folders,
313
+ (err, data) => {
314
+ if (err) reject(err);
315
+ else resolve(data);
316
+ }
317
+ );
318
+ });
199
319
  }
200
320
  /**
201
321
  * Fetches message history for a thread.
@@ -203,14 +323,29 @@ var ConduitThreadsAPI = class {
203
323
  * @param limit - Number of messages to return.
204
324
  */
205
325
  getHistory(threadID, limit) {
206
- return this.bot.ctx.api.getThreadHistory(threadID, limit);
326
+ return new Promise((resolve, reject) => {
327
+ this.bot.ctx.api.getThreadHistory(
328
+ threadID,
329
+ limit,
330
+ void 0,
331
+ (err, data) => {
332
+ if (err) reject(err);
333
+ else resolve(data);
334
+ }
335
+ );
336
+ });
207
337
  }
208
338
  /**
209
339
  * Searches for threads by name or keyword.
210
340
  * @param query - The search query string.
211
341
  */
212
342
  search(query) {
213
- return this.bot.ctx.api.searchForThread(query);
343
+ return new Promise((resolve, reject) => {
344
+ this.bot.ctx.api.searchForThread(query, (err, data) => {
345
+ if (err) reject(err);
346
+ else resolve(data);
347
+ });
348
+ });
214
349
  }
215
350
  /**
216
351
  * Creates a new group conversation.
@@ -218,7 +353,12 @@ var ConduitThreadsAPI = class {
218
353
  * @param name - Optional group name.
219
354
  */
220
355
  createGroup(userIDs, name) {
221
- return this.bot.ctx.api.createNewGroup(userIDs, name);
356
+ return new Promise((resolve, reject) => {
357
+ this.bot.ctx.api.createNewGroup(userIDs, name, (err, data) => {
358
+ if (err) reject(err);
359
+ else resolve(data);
360
+ });
361
+ });
222
362
  }
223
363
  /**
224
364
  * Adds a user to an existing group thread.
@@ -226,7 +366,12 @@ var ConduitThreadsAPI = class {
226
366
  * @param threadID - The target group thread ID.
227
367
  */
228
368
  addUser(userID, threadID) {
229
- return this.bot.ctx.api.addUserToGroup(userID, threadID);
369
+ return new Promise((resolve, reject) => {
370
+ this.bot.ctx.api.addUserToGroup(userID, threadID, (err) => {
371
+ if (err) reject(err);
372
+ else resolve(null);
373
+ });
374
+ });
230
375
  }
231
376
  /**
232
377
  * Removes a user from a group thread.
@@ -234,7 +379,12 @@ var ConduitThreadsAPI = class {
234
379
  * @param threadID - The target group thread ID.
235
380
  */
236
381
  removeUser(userID, threadID) {
237
- return this.bot.ctx.api.removeUserFromGroup(userID, threadID);
382
+ return new Promise((resolve, reject) => {
383
+ this.bot.ctx.api.removeUserFromGroup(userID, threadID, (err) => {
384
+ if (err) reject(err);
385
+ else resolve(null);
386
+ });
387
+ });
238
388
  }
239
389
  /**
240
390
  * Promotes or demotes a user's admin status in a group.
@@ -243,7 +393,17 @@ var ConduitThreadsAPI = class {
243
393
  * @param admin - `true` to promote, `false` to demote.
244
394
  */
245
395
  changeAdminStatus(userID, threadID, admin) {
246
- return this.bot.ctx.api.changeAdminStatus(userID, threadID, admin);
396
+ return new Promise((resolve, reject) => {
397
+ this.bot.ctx.api.changeAdminStatus(
398
+ userID,
399
+ threadID,
400
+ admin,
401
+ (err) => {
402
+ if (err) reject(err);
403
+ else resolve(null);
404
+ }
405
+ );
406
+ });
247
407
  }
248
408
  /**
249
409
  * Updates the group's profile image.
@@ -251,7 +411,12 @@ var ConduitThreadsAPI = class {
251
411
  * @param threadID - The target group thread ID.
252
412
  */
253
413
  changeGroupImage(image, threadID) {
254
- return this.bot.ctx.api.changeGroupImage(image, threadID);
414
+ return new Promise((resolve, reject) => {
415
+ this.bot.ctx.api.changeGroupImage(image, threadID, (err) => {
416
+ if (err) reject(err);
417
+ else resolve(null);
418
+ });
419
+ });
255
420
  }
256
421
  /**
257
422
  * Sets a participant's nickname in a thread.
@@ -260,7 +425,17 @@ var ConduitThreadsAPI = class {
260
425
  * @param userID - The target user ID.
261
426
  */
262
427
  changeNickname(nickname, threadID, userID) {
263
- return this.bot.ctx.api.changeNickname(nickname, threadID, userID);
428
+ return new Promise((resolve, reject) => {
429
+ this.bot.ctx.api.changeNickname(
430
+ nickname,
431
+ threadID,
432
+ userID,
433
+ (err) => {
434
+ if (err) reject(err);
435
+ else resolve(null);
436
+ }
437
+ );
438
+ });
264
439
  }
265
440
  /**
266
441
  * Changes the title of a group thread.
@@ -268,7 +443,12 @@ var ConduitThreadsAPI = class {
268
443
  * @param threadID - The target group thread ID.
269
444
  */
270
445
  setTitle(title, threadID) {
271
- return this.bot.ctx.api.setTitle(title, threadID);
446
+ return new Promise((resolve, reject) => {
447
+ this.bot.ctx.api.setTitle(title, threadID, (err) => {
448
+ if (err) reject(err);
449
+ else resolve(null);
450
+ });
451
+ });
272
452
  }
273
453
  /**
274
454
  * Creates a poll in a thread.
@@ -277,14 +457,29 @@ var ConduitThreadsAPI = class {
277
457
  * @param options - Array of answer options.
278
458
  */
279
459
  createPoll(title, threadID, options) {
280
- return this.bot.ctx.api.createPoll(title, threadID, options);
460
+ return new Promise((resolve, reject) => {
461
+ this.bot.ctx.api.createPoll(
462
+ title,
463
+ threadID,
464
+ options,
465
+ (err, data) => {
466
+ if (err) reject(err);
467
+ else resolve(data);
468
+ }
469
+ );
470
+ });
281
471
  }
282
472
  /**
283
473
  * Deletes a thread.
284
474
  * @param threadID - The thread ID to delete.
285
475
  */
286
476
  delete(threadID) {
287
- return this.bot.ctx.api.deleteThread(threadID);
477
+ return new Promise((resolve, reject) => {
478
+ this.bot.ctx.api.deleteThread(threadID, (err) => {
479
+ if (err) reject(err);
480
+ else resolve(null);
481
+ });
482
+ });
288
483
  }
289
484
  /**
290
485
  * Mutes or unmutes notifications for a thread.
@@ -292,7 +487,12 @@ var ConduitThreadsAPI = class {
292
487
  * @param muteUntil - Timestamp (ms) to mute until. Pass `-1` to mute indefinitely, `0` to unmute.
293
488
  */
294
489
  mute(threadID, muteUntil) {
295
- return this.bot.ctx.api.muteThread(threadID, muteUntil);
490
+ return new Promise((resolve, reject) => {
491
+ this.bot.ctx.api.muteThread(threadID, muteUntil, (err) => {
492
+ if (err) reject(err);
493
+ else resolve(null);
494
+ });
495
+ });
296
496
  }
297
497
  /**
298
498
  * Accepts or declines a message request.
@@ -300,7 +500,12 @@ var ConduitThreadsAPI = class {
300
500
  * @param accept - `true` to accept, `false` to decline.
301
501
  */
302
502
  handleMessageRequest(threadID, accept) {
303
- return this.bot.ctx.api.handleMessageRequest(threadID, accept);
503
+ return new Promise((resolve, reject) => {
504
+ this.bot.ctx.api.handleMessageRequest(threadID, accept, (err) => {
505
+ if (err) reject(err);
506
+ else resolve(null);
507
+ });
508
+ });
304
509
  }
305
510
  };
306
511
 
@@ -315,20 +520,38 @@ var ConduitUsersAPI = class {
315
520
  * @param userID - A single user ID or an array of user IDs.
316
521
  */
317
522
  getInfo(userID) {
318
- return this.bot.ctx.api.getUserInfo(userID);
523
+ return new Promise((resolve, reject) => {
524
+ this.bot.ctx.api.getUserInfo(
525
+ Array.isArray(userID) ? userID : [userID],
526
+ (err, data) => {
527
+ if (err) reject(err);
528
+ else resolve(data);
529
+ }
530
+ );
531
+ });
319
532
  }
320
533
  /**
321
534
  * Resolves a vanity URL or username to a Facebook user ID.
322
535
  * @param vanity - The vanity name or profile URL slug.
323
536
  */
324
537
  getID(vanity) {
325
- return this.bot.ctx.api.getUserID(vanity);
538
+ return new Promise((resolve, reject) => {
539
+ this.bot.ctx.api.getUserID(vanity, (err, data) => {
540
+ if (err) reject(err);
541
+ else resolve(data);
542
+ });
543
+ });
326
544
  }
327
545
  /**
328
546
  * Returns the authenticated user's friends list.
329
547
  */
330
548
  getFriendsList() {
331
- return this.bot.ctx.api.getFriendsList();
549
+ return new Promise((resolve, reject) => {
550
+ this.bot.ctx.api.getFriendsList((err, data) => {
551
+ if (err) reject(err);
552
+ else resolve(data);
553
+ });
554
+ });
332
555
  }
333
556
  };
334
557
 
@@ -350,7 +573,12 @@ var ConduitAccountAPI = class {
350
573
  * @param block - `true` to block, `false` to unblock.
351
574
  */
352
575
  blockUser(userID, block) {
353
- return this.bot.ctx.api.changeBlockedStatus(userID, block);
576
+ return new Promise((resolve, reject) => {
577
+ this.bot.ctx.api.changeBlockedStatus(userID, block, (err) => {
578
+ if (err) reject(err);
579
+ else resolve(null);
580
+ });
581
+ });
354
582
  }
355
583
  /**
356
584
  * Accepts or declines a friend request.
@@ -358,20 +586,35 @@ var ConduitAccountAPI = class {
358
586
  * @param accept - `true` to accept, `false` to decline.
359
587
  */
360
588
  handleFriendRequest(userID, accept) {
361
- return this.bot.ctx.api.handleFriendRequest(userID, accept);
589
+ return new Promise((resolve, reject) => {
590
+ this.bot.ctx.api.handleFriendRequest(userID, accept, (err) => {
591
+ if (err) reject(err);
592
+ else resolve(null);
593
+ });
594
+ });
362
595
  }
363
596
  /**
364
597
  * Removes a user from the friends list.
365
598
  * @param userID - The target user ID.
366
599
  */
367
600
  unfriend(userID) {
368
- return this.bot.ctx.api.unfriend(userID);
601
+ return new Promise((resolve, reject) => {
602
+ this.bot.ctx.api.unfriend(userID, (err) => {
603
+ if (err) reject(err);
604
+ else resolve(null);
605
+ });
606
+ });
369
607
  }
370
608
  /**
371
609
  * Ends the current session and invalidates cookies.
372
610
  */
373
611
  logout() {
374
- return this.bot.ctx.api.logout();
612
+ return new Promise((resolve, reject) => {
613
+ this.bot.ctx.api.logout((err) => {
614
+ if (err) reject(err);
615
+ else resolve(null);
616
+ });
617
+ });
375
618
  }
376
619
  };
377
620