@hiroosy/baileys-lite 0.4.4 → 0.4.6

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.
@@ -5921,6 +5921,7 @@ export namespace proto {
5921
5921
  encCommentMessage?: (proto.Message.IEncCommentMessage|null);
5922
5922
  bcallMessage?: (proto.Message.IBCallMessage|null);
5923
5923
  lottieStickerMessage?: (proto.Message.IFutureProofMessage|null);
5924
+ audioStickerMessage?: (proto.Message.IFutureProofMessage|null);
5924
5925
  eventMessage?: (proto.Message.IEventMessage|null);
5925
5926
  encEventResponseMessage?: (proto.Message.IEncEventResponseMessage|null);
5926
5927
  commentMessage?: (proto.Message.ICommentMessage|null);
@@ -6032,6 +6033,7 @@ export namespace proto {
6032
6033
  public encCommentMessage?: (proto.Message.IEncCommentMessage|null);
6033
6034
  public bcallMessage?: (proto.Message.IBCallMessage|null);
6034
6035
  public lottieStickerMessage?: (proto.Message.IFutureProofMessage|null);
6036
+ public audioStickerMessage?: (proto.Message.IFutureProofMessage|null);
6035
6037
  public eventMessage?: (proto.Message.IEventMessage|null);
6036
6038
  public encEventResponseMessage?: (proto.Message.IEncEventResponseMessage|null);
6037
6039
  public commentMessage?: (proto.Message.ICommentMessage|null);
@@ -10266,6 +10268,7 @@ export namespace proto {
10266
10268
  accessibilityLabel?: (string|null);
10267
10269
  premium?: (number|null);
10268
10270
  emojis?: (string|null);
10271
+ audioMessage?: (proto.Message.IAudioMessage|null);
10269
10272
  }
10270
10273
 
10271
10274
  class StickerMessage implements IStickerMessage {
@@ -10292,6 +10295,7 @@ export namespace proto {
10292
10295
  public accessibilityLabel?: (string|null);
10293
10296
  public premium?: (number|null);
10294
10297
  public emojis?: (string|null);
10298
+ public audioMessage?: (proto.Message.IAudioMessage|null);
10295
10299
  public static create(properties?: proto.Message.IStickerMessage): proto.Message.StickerMessage;
10296
10300
  public static encode(m: proto.Message.IStickerMessage, w?: $protobuf.Writer): $protobuf.Writer;
10297
10301
  public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): proto.Message.StickerMessage;
@@ -67,6 +67,7 @@ Message.prototype.messageHistoryBundle = null;
67
67
  Message.prototype.encCommentMessage = null;
68
68
  Message.prototype.bcallMessage = null;
69
69
  Message.prototype.lottieStickerMessage = null;
70
+ Message.prototype.audioStickerMessage = null;
70
71
  Message.prototype.eventMessage = null;
71
72
  Message.prototype.encEventResponseMessage = null;
72
73
  Message.prototype.commentMessage = null;
@@ -361,6 +362,10 @@ Object.defineProperty(Message.prototype, "_lottieStickerMessage", {
361
362
  get: $util.oneOfGetter($oneOfFields = ["lottieStickerMessage"]),
362
363
  set: $util.oneOfSetter($oneOfFields)
363
364
  });
365
+ Object.defineProperty(Message.prototype, "_audioStickerMessage", {
366
+ get: $util.oneOfGetter($oneOfFields = ["audioStickerMessage"]),
367
+ set: $util.oneOfSetter($oneOfFields)
368
+ });
364
369
  Object.defineProperty(Message.prototype, "_eventMessage", {
365
370
  get: $util.oneOfGetter($oneOfFields = ["eventMessage"]),
366
371
  set: $util.oneOfSetter($oneOfFields)
@@ -671,6 +676,8 @@ if (m.bcallMessage != null && Object.hasOwnProperty.call(m, "bcallMessage"))
671
676
  $root.proto.Message.BCallMessage.encode(m.bcallMessage, w.uint32(578).fork()).ldelim();
672
677
  if (m.lottieStickerMessage != null && Object.hasOwnProperty.call(m, "lottieStickerMessage"))
673
678
  $root.proto.Message.FutureProofMessage.encode(m.lottieStickerMessage, w.uint32(594).fork()).ldelim();
679
+ if (m.audioStickerMessage != null && Object.hasOwnProperty.call(m, "audioStickerMessage"))
680
+ $root.proto.Message.FutureProofMessage.encode(m.audioStickerMessage, w.uint32(1074).fork()).ldelim();
674
681
  if (m.eventMessage != null && Object.hasOwnProperty.call(m, "eventMessage"))
675
682
  $root.proto.Message.EventMessage.encode(m.eventMessage, w.uint32(602).fork()).ldelim();
676
683
  if (m.encEventResponseMessage != null && Object.hasOwnProperty.call(m, "encEventResponseMessage"))
@@ -1024,6 +1031,10 @@ case 74: {
1024
1031
  m.lottieStickerMessage = $root.proto.Message.FutureProofMessage.decode(r, r.uint32(), undefined, n + 1);
1025
1032
  break;
1026
1033
  }
1034
+ case 134: {
1035
+ m.audioStickerMessage = $root.proto.Message.FutureProofMessage.decode(r, r.uint32(), undefined, n + 1);
1036
+ break;
1037
+ }
1027
1038
  case 75: {
1028
1039
  m.eventMessage = $root.proto.Message.EventMessage.decode(r, r.uint32(), undefined, n + 1);
1029
1040
  break;
@@ -1527,6 +1538,11 @@ if (typeof d.lottieStickerMessage !== "object")
1527
1538
  throw TypeError(".proto.Message.lottieStickerMessage: object expected");
1528
1539
  m.lottieStickerMessage = $root.proto.Message.FutureProofMessage.fromObject(d.lottieStickerMessage, n + 1);
1529
1540
  }
1541
+ if (d.audioStickerMessage != null) {
1542
+ if (typeof d.audioStickerMessage !== "object")
1543
+ throw TypeError(".proto.Message.audioStickerMessage: object expected");
1544
+ m.audioStickerMessage = $root.proto.Message.FutureProofMessage.fromObject(d.audioStickerMessage, n + 1);
1545
+ }
1530
1546
  if (d.eventMessage != null) {
1531
1547
  if (typeof d.eventMessage !== "object")
1532
1548
  throw TypeError(".proto.Message.eventMessage: object expected");
@@ -2068,6 +2084,11 @@ d.lottieStickerMessage = $root.proto.Message.FutureProofMessage.toObject(m.lotti
2068
2084
  if (o.oneofs)
2069
2085
  d._lottieStickerMessage = "lottieStickerMessage";
2070
2086
  }
2087
+ if (m.audioStickerMessage != null && m.hasOwnProperty("audioStickerMessage")) {
2088
+ d.audioStickerMessage = $root.proto.Message.FutureProofMessage.toObject(m.audioStickerMessage, o);
2089
+ if (o.oneofs)
2090
+ d._audioStickerMessage = "audioStickerMessage";
2091
+ }
2071
2092
  if (m.eventMessage != null && m.hasOwnProperty("eventMessage")) {
2072
2093
  d.eventMessage = $root.proto.Message.EventMessage.toObject(m.eventMessage, o);
2073
2094
  if (o.oneofs)
@@ -29175,6 +29196,7 @@ StickerMessage.prototype.isLottie = null;
29175
29196
  StickerMessage.prototype.accessibilityLabel = null;
29176
29197
  StickerMessage.prototype.premium = null;
29177
29198
  StickerMessage.prototype.emojis = null;
29199
+ StickerMessage.prototype.audioMessage = null;
29178
29200
  let $oneOfFields;
29179
29201
  Object.defineProperty(StickerMessage.prototype, "_url", {
29180
29202
  get: $util.oneOfGetter($oneOfFields = ["url"]),
@@ -29264,6 +29286,10 @@ Object.defineProperty(StickerMessage.prototype, "_emojis", {
29264
29286
  get: $util.oneOfGetter($oneOfFields = ["emojis"]),
29265
29287
  set: $util.oneOfSetter($oneOfFields)
29266
29288
  });
29289
+ Object.defineProperty(StickerMessage.prototype, "_audioMessage", {
29290
+ get: $util.oneOfGetter($oneOfFields = ["audioMessage"]),
29291
+ set: $util.oneOfSetter($oneOfFields)
29292
+ });
29267
29293
  StickerMessage.create = function create(properties) {
29268
29294
  return new StickerMessage(properties);
29269
29295
  };
@@ -29314,6 +29340,8 @@ if (m.premium != null && Object.hasOwnProperty.call(m, "premium"))
29314
29340
  w.uint32(192).int32(m.premium);
29315
29341
  if (m.emojis != null && Object.hasOwnProperty.call(m, "emojis"))
29316
29342
  w.uint32(202).string(m.emojis);
29343
+ if (m.audioMessage != null && Object.hasOwnProperty.call(m, "audioMessage"))
29344
+ $root.proto.Message.AudioMessage.encode(m.audioMessage, w.uint32(210).fork()).ldelim();
29317
29345
  return w;
29318
29346
  };
29319
29347
  StickerMessage.decode = function decode(r, l, e, n) {
@@ -29417,6 +29445,10 @@ case 25: {
29417
29445
  m.emojis = r.string();
29418
29446
  break;
29419
29447
  }
29448
+ case 26: {
29449
+ m.audioMessage = $root.proto.Message.AudioMessage.decode(r, r.uint32(), undefined, n + 1);
29450
+ break;
29451
+ }
29420
29452
  default:
29421
29453
  r.skipType(t & 7, n);
29422
29454
  break;
@@ -29536,6 +29568,11 @@ m.premium = d.premium | 0;
29536
29568
  if (d.emojis != null) {
29537
29569
  m.emojis = String(d.emojis);
29538
29570
  }
29571
+ if (d.audioMessage != null) {
29572
+ if (typeof d.audioMessage !== "object")
29573
+ throw TypeError(".proto.Message.StickerMessage.audioMessage: object expected");
29574
+ m.audioMessage = $root.proto.Message.AudioMessage.fromObject(d.audioMessage, n + 1);
29575
+ }
29539
29576
  return m;
29540
29577
  };
29541
29578
  StickerMessage.toObject = function toObject(m, o) {
@@ -29661,6 +29698,11 @@ d.emojis = m.emojis;
29661
29698
  if (o.oneofs)
29662
29699
  d._emojis = "emojis";
29663
29700
  }
29701
+ if (m.audioMessage != null && m.hasOwnProperty("audioMessage")) {
29702
+ d.audioMessage = $root.proto.Message.AudioMessage.toObject(m.audioMessage, o);
29703
+ if (o.oneofs)
29704
+ d._audioMessage = "audioMessage";
29705
+ }
29664
29706
  return d;
29665
29707
  };
29666
29708
  StickerMessage.prototype.toJSON = function toJSON() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiroosy/baileys-lite",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "A Lightweight Baileys built with Pure NodeJs 18+",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,6 +20,7 @@ import {
20
20
  getCompanionPlatformId,
21
21
  getErrorCodeFromStreamError,
22
22
  getNextPreKeysNode,
23
+ isAndroidBrowser,
23
24
  makeNoiseHandler,
24
25
  promiseTimeout,
25
26
  signedKeyPair,
@@ -344,7 +345,7 @@ export const makeSocket = config => {
344
345
  const keyEnc = noise.processHandshake(handshake, creds.noiseKey)
345
346
  let node
346
347
  if (!creds.me) {
347
- node = generateRegistrationNode(creds, config)
348
+ node = generateRegistrationNode(creds, config, false)
348
349
  logger.info({ node }, 'not logged in, attempting registration...')
349
350
  } else {
350
351
  node = generateLoginNode(creds.me.id, config)
@@ -618,7 +619,7 @@ export const makeSocket = config => {
618
619
  authState.creds.me = { id: jidEncode(phone, 's.whatsapp.net'), name: '~' }
619
620
  ev.emit('creds.update', authState.creds)
620
621
  try {
621
- await sendNode({
622
+ await query({
622
623
  tag: 'iq',
623
624
  attrs: { to: S_WHATSAPP_NET, type: 'set', id: generateMessageTag(), xmlns: 'md' },
624
625
  content: [
@@ -629,7 +630,7 @@ export const makeSocket = config => {
629
630
  { tag: 'link_code_pairing_wrapped_companion_ephemeral_pub', attrs: {}, content: await generatePairingKey() },
630
631
  { tag: 'companion_server_auth_key_pub', attrs: {}, content: authState.creds.noiseKey.public },
631
632
  { tag: 'companion_platform_id', attrs: {}, content: getCompanionPlatformId(browser) },
632
- { tag: 'companion_platform_display', attrs: {}, content: `${browser[1]} (${browser[0]})` },
633
+ { tag: 'companion_platform_display', attrs: {}, content: isAndroidBrowser(browser) ? `Chrome (${browser[1]})` : `${browser[1]} (${browser[0]})` },
633
634
  { tag: 'link_code_pairing_nonce', attrs: {}, content: '0' }
634
635
  ]
635
636
  }
@@ -1476,9 +1476,14 @@ export const generateWAMessageFromContent = (jid, message, options) => {
1476
1476
  const participant = quoted.key.fromMe ? userJid : quoted.participant || quoted.key.participant || quoted.key.remoteJid
1477
1477
  let quotedMsg = normalizeMessageContent(quoted.message)
1478
1478
  const msgType = getContentType(quotedMsg)
1479
- const quotedContent = { ...quotedMsg[msgType] }
1480
- delete quotedContent.contextInfo
1481
- quotedMsg = proto.Message.create({ [msgType]: quotedContent })
1479
+ const quotedBody = quotedMsg[msgType]
1480
+ if (typeof quotedBody === 'string') {
1481
+ quotedMsg = proto.Message.create({ [msgType]: quotedBody })
1482
+ } else {
1483
+ const quotedContent = { ...quotedBody }
1484
+ delete quotedContent.contextInfo
1485
+ quotedMsg = proto.Message.create({ [msgType]: quotedContent })
1486
+ }
1482
1487
  const patch = { participant: jidNormalizedUser(participant), stanzaId: quoted.key.id, quotedMessage: quotedMsg }
1483
1488
  if (!isNewsletter && jid !== quoted.key.remoteJid) patch.remoteJid = quoted.key.remoteJid
1484
1489
  mergeContextInfo(patch)
@@ -342,7 +342,7 @@ export const getStatusFromReceiptType = type => {
342
342
  return status
343
343
  }
344
344
 
345
- const CODE_MAP = { conflict: DisconnectReason.connectionReplaced }
345
+ const CODE_MAP = { conflict: DisconnectReason.connectionReplaced, ack: DisconnectReason.restartRequired }
346
346
 
347
347
  export const getErrorCodeFromStreamError = node => {
348
348
  const [reasonNode] = getAllBinaryNodeChildren(node)
@@ -356,7 +356,7 @@ export const getErrorCodeFromStreamError = node => {
356
356
  reason = 'device removed'
357
357
  }
358
358
  }
359
- if (statusCode === DisconnectReason.restartRequired) reason = 'restart required'
359
+ if (statusCode === DisconnectReason.restartRequired && reason !== 'ack') reason = 'restart required'
360
360
  return { reason, statusCode }
361
361
  }
362
362
 
@@ -484,6 +484,8 @@ export const getCompanionWebClientType = ([os, browserName]) => {
484
484
 
485
485
  export const getCompanionPlatformId = browser => getCompanionWebClientType(browser).toString()
486
486
 
487
+ export const isAndroidBrowser = browser => browser[1].toLocaleLowerCase().includes('android')
488
+
487
489
  export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) =>
488
490
  'https://wa.me/settings/linked_devices#' + [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',')
489
491
 
@@ -888,11 +890,9 @@ const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0])
888
890
  const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
889
891
  const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
890
892
 
891
- const getUserAgent = config => ({
893
+ const getUserAgent = (config, android) => ({
892
894
  appVersion: { primary: config.version[0], secondary: config.version[1], tertiary: config.version[2] },
893
- platform: config.browser[1].toLocaleLowerCase().includes('android')
894
- ? proto.ClientPayload.UserAgent.Platform.ANDROID
895
- : proto.ClientPayload.UserAgent.Platform.WEB,
895
+ platform: android ? proto.ClientPayload.UserAgent.Platform.ANDROID : proto.ClientPayload.UserAgent.Platform.WEB,
896
896
  releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
897
897
  osVersion: '0.1',
898
898
  device: 'Desktop',
@@ -916,20 +916,20 @@ const getWebInfo = config => {
916
916
  return { webSubPlatform }
917
917
  }
918
918
 
919
- const getClientPayload = config => {
919
+ const getClientPayload = (config, android) => {
920
920
  const payload = {
921
921
  connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
922
922
  connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
923
- userAgent: getUserAgent(config)
923
+ userAgent: getUserAgent(config, android)
924
924
  }
925
- if (!config.browser[1].toLocaleLowerCase().includes('android')) payload.webInfo = getWebInfo(config)
925
+ if (!android) payload.webInfo = getWebInfo(config)
926
926
  if (config.pushName) payload.pushName = config.pushName
927
927
  return payload
928
928
  }
929
929
 
930
- export const generateLoginNode = (userJid, config) => {
930
+ export const generateLoginNode = (userJid, config, android = isAndroidBrowser(config.browser)) => {
931
931
  const { user, device } = jidDecode(userJid)
932
- const payload = { ...getClientPayload(config), passive: true, pull: true, username: +user, device, lidDbMigrated: false }
932
+ const payload = { ...getClientPayload(config, android), passive: true, pull: true, username: +user, device, lidDbMigrated: false }
933
933
  return proto.ClientPayload.fromObject(payload)
934
934
  }
935
935
 
@@ -939,7 +939,7 @@ const getPlatformType = platform => {
939
939
  return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.CHROME
940
940
  }
941
941
 
942
- export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
942
+ export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config, android = isAndroidBrowser(config.browser)) => {
943
943
  const appVersionBuf = createHash('md5').update(config.version.join('.')).digest()
944
944
  const companion = {
945
945
  os: config.browser[0],
@@ -966,7 +966,7 @@ export const generateRegistrationNode = ({ registrationId, signedPreKey, signedI
966
966
  }
967
967
  const companionProto = proto.DeviceProps.encode(companion).finish()
968
968
  const registerPayload = {
969
- ...getClientPayload(config),
969
+ ...getClientPayload(config, android),
970
970
  passive: false,
971
971
  pull: false,
972
972
  devicePairingData: {