@pacoyang/wechaty-puppet-wechat 0.28.5 → 0.28.7

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.
Files changed (47) hide show
  1. package/dist/examples/demo.js.map +1 -1
  2. package/dist/scripts/retry-unit-tests.js +1 -1
  3. package/dist/scripts/retry-unit-tests.js.map +1 -1
  4. package/dist/src/bridge.d.ts +40 -2
  5. package/dist/src/bridge.d.ts.map +1 -1
  6. package/dist/src/bridge.js +143 -2
  7. package/dist/src/bridge.js.map +1 -1
  8. package/dist/src/bridge.spec.js.map +1 -1
  9. package/dist/src/event.d.ts.map +1 -1
  10. package/dist/src/event.js +9 -1
  11. package/dist/src/event.js.map +1 -1
  12. package/dist/src/event.spec.js.map +1 -1
  13. package/dist/src/firer.d.ts.map +1 -1
  14. package/dist/src/firer.js +12 -3
  15. package/dist/src/firer.js.map +1 -1
  16. package/dist/src/puppet-wechat.d.ts +78 -2
  17. package/dist/src/puppet-wechat.d.ts.map +1 -1
  18. package/dist/src/puppet-wechat.js +302 -16
  19. package/dist/src/puppet-wechat.js.map +1 -1
  20. package/dist/src/puppet-wechat.spec.js.map +1 -1
  21. package/dist/src/pure-function-helpers/message-extname.js.map +1 -1
  22. package/dist/src/pure-function-helpers/message-filename.js.map +1 -1
  23. package/dist/src/pure-function-helpers/message-raw-payload-parser.js.map +1 -1
  24. package/dist/src/pure-function-helpers/normalize-scan-status.js.map +1 -1
  25. package/dist/src/pure-function-helpers/normalize-scan-status.spec.js.map +1 -1
  26. package/dist/src/pure-function-helpers/web-message-type.js.map +1 -1
  27. package/dist/src/pure-function-helpers/xml.js.map +1 -1
  28. package/dist/src/session-monitor.d.ts +74 -0
  29. package/dist/src/session-monitor.d.ts.map +1 -0
  30. package/dist/src/session-monitor.js +122 -0
  31. package/dist/src/session-monitor.js.map +1 -0
  32. package/dist/src/web-schemas.js +2 -2
  33. package/dist/src/web-schemas.js.map +1 -1
  34. package/dist/src/wechaty-bro.js +58 -3
  35. package/dist/tests/puppeteer-friendship.spec.js +2 -2
  36. package/dist/tests/puppeteer-friendship.spec.js.map +1 -1
  37. package/dist/tests/puppeteer-message.spec.js.map +1 -1
  38. package/dist/tests/puppeteer-room.spec.js.map +1 -1
  39. package/dist/tests/puppeteer.spec.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/bridge.ts +176 -4
  42. package/src/event.ts +9 -1
  43. package/src/firer.ts +12 -3
  44. package/src/puppet-wechat.ts +344 -12
  45. package/src/session-monitor.ts +165 -0
  46. package/src/wechaty-bro.js +58 -3
  47. package/tsconfig.json +0 -1
@@ -268,6 +268,57 @@
268
268
  setTimeout(() => checkScan(), 1000)
269
269
  }
270
270
 
271
+ /**
272
+ * chatFactory.sendMessage() posts in the background and later sets the
273
+ * message's MMStatus to success or failure. Wait for that, so a message
274
+ * WeChat refused is reported as failed instead of sent.
275
+ */
276
+ // the web app retries a send 3 times, 15s each, before it marks it failed
277
+ const SEND_CONFIRM_TIMEOUT = 75 * 1000
278
+
279
+ function sentResult (m) {
280
+ const confFactory = WechatyBro.glue.confFactory
281
+ const started = Date.now()
282
+ return new Promise(function (resolve) {
283
+ (function check () {
284
+ if (m.MMStatus === confFactory.MSG_SEND_STATUS_SUCC) {
285
+ return resolve(true)
286
+ }
287
+ if (m.MMStatus === confFactory.MSG_SEND_STATUS_FAIL) {
288
+ return resolve('WeChat refused the message')
289
+ }
290
+ if (Date.now() - started > SEND_CONFIRM_TIMEOUT) {
291
+ return resolve('no answer from WeChat in ' + (SEND_CONFIRM_TIMEOUT / 1000) + 's')
292
+ }
293
+ setTimeout(check, 200)
294
+ })()
295
+ })
296
+ }
297
+
298
+ function health () {
299
+ const loginScope = WechatyBro.glue.loginScope
300
+ let roomCount = null
301
+ try {
302
+ roomCount = WechatyBro.glue.contactFactory.getAllChatroomContact().length
303
+ } catch (e) {}
304
+ return {
305
+ loginState : loginState(),
306
+ loginCode : loginScope ? loginScope.code : null,
307
+ now : Date.now(),
308
+ roomCount,
309
+ userName : getUserName(),
310
+ }
311
+ }
312
+
313
+ function roomTopicList () {
314
+ return WechatyBro.glue.contactFactory.getAllChatroomContact()
315
+ .map(r => ({
316
+ id : r.UserName,
317
+ memberCount : (r.MemberList || []).length,
318
+ topic : r.NickName || '',
319
+ }))
320
+ }
321
+
271
322
  function ding (data) {
272
323
  log('recv ding')
273
324
  return data || 'dong'
@@ -431,11 +482,11 @@
431
482
 
432
483
  chatFactory.appendMessage(m)
433
484
  chatFactory.sendMessage(m)
485
+ return sentResult(m)
434
486
  } catch (e) {
435
487
  log('sendMedia() exception: ' + e.message)
436
488
  return false
437
489
  }
438
- return true
439
490
  }
440
491
 
441
492
  function forward (baseData, patchData) {
@@ -455,11 +506,11 @@
455
506
 
456
507
  chatFactory.appendMessage(m)
457
508
  chatFactory.sendMessage(m)
509
+ return sentResult(m)
458
510
  } catch (e) {
459
511
  log('forward() exception: ' + e.message)
460
512
  return false
461
513
  }
462
- return true
463
514
  }
464
515
 
465
516
  function send (ToUserName, Content) {
@@ -478,11 +529,11 @@
478
529
  })
479
530
  chatFactory.appendMessage(m)
480
531
  chatFactory.sendMessage(m)
532
+ return sentResult(m)
481
533
  } catch (e) {
482
534
  log('send() exception: ' + e.message)
483
535
  return false
484
536
  }
485
- return true
486
537
  }
487
538
 
488
539
  function getMessage (id) {
@@ -811,6 +862,7 @@
811
862
 
812
863
  scanCode : null,
813
864
  heartBeatTimmer : null,
865
+
814
866
  },
815
867
 
816
868
  // funcs
@@ -846,6 +898,9 @@
846
898
  roomList,
847
899
  roomDelMember,
848
900
  roomModTopic,
901
+ roomTopicList,
902
+
903
+ health,
849
904
 
850
905
  // for Friend Request
851
906
  verifyUserRequest,
package/tsconfig.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "dom",
7
7
  "esnext",
8
8
  ],
9
- "useUnknownInCatchVariables": false,
10
9
  },
11
10
  "exclude": [
12
11
  "node_modules/",