@juzi/wechaty 1.0.4 → 1.0.5

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 (56) hide show
  1. package/dist/cjs/src/package-json.js +4 -4
  2. package/dist/cjs/src/sayable/deliver-sayable.d.ts +2 -2
  3. package/dist/cjs/src/sayable/deliver-sayable.d.ts.map +1 -1
  4. package/dist/cjs/src/sayable/deliver-sayable.js +5 -2
  5. package/dist/cjs/src/sayable/deliver-sayable.js.map +1 -1
  6. package/dist/cjs/src/sayable/mod.d.ts +2 -2
  7. package/dist/cjs/src/sayable/mod.d.ts.map +1 -1
  8. package/dist/cjs/src/sayable/mod.js.map +1 -1
  9. package/dist/cjs/src/sayable/types.d.ts +9 -3
  10. package/dist/cjs/src/sayable/types.d.ts.map +1 -1
  11. package/dist/cjs/src/sayable/types.js +8 -0
  12. package/dist/cjs/src/sayable/types.js.map +1 -1
  13. package/dist/cjs/src/user-modules/contact.d.ts +2 -2
  14. package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
  15. package/dist/cjs/src/user-modules/contact.js +6 -2
  16. package/dist/cjs/src/user-modules/contact.js.map +1 -1
  17. package/dist/cjs/src/user-modules/message.d.ts +7 -0
  18. package/dist/cjs/src/user-modules/message.d.ts.map +1 -1
  19. package/dist/cjs/src/user-modules/message.js +31 -0
  20. package/dist/cjs/src/user-modules/message.js.map +1 -1
  21. package/dist/cjs/src/user-modules/room.d.ts +3 -1
  22. package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
  23. package/dist/cjs/src/user-modules/room.js +21 -3
  24. package/dist/cjs/src/user-modules/room.js.map +1 -1
  25. package/dist/esm/src/package-json.js +4 -4
  26. package/dist/esm/src/sayable/deliver-sayable.d.ts +2 -2
  27. package/dist/esm/src/sayable/deliver-sayable.d.ts.map +1 -1
  28. package/dist/esm/src/sayable/deliver-sayable.js +5 -2
  29. package/dist/esm/src/sayable/deliver-sayable.js.map +1 -1
  30. package/dist/esm/src/sayable/mod.d.ts +2 -2
  31. package/dist/esm/src/sayable/mod.d.ts.map +1 -1
  32. package/dist/esm/src/sayable/mod.js.map +1 -1
  33. package/dist/esm/src/sayable/types.d.ts +9 -3
  34. package/dist/esm/src/sayable/types.d.ts.map +1 -1
  35. package/dist/esm/src/sayable/types.js +6 -1
  36. package/dist/esm/src/sayable/types.js.map +1 -1
  37. package/dist/esm/src/user-modules/contact.d.ts +2 -2
  38. package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
  39. package/dist/esm/src/user-modules/contact.js +6 -2
  40. package/dist/esm/src/user-modules/contact.js.map +1 -1
  41. package/dist/esm/src/user-modules/message.d.ts +7 -0
  42. package/dist/esm/src/user-modules/message.d.ts.map +1 -1
  43. package/dist/esm/src/user-modules/message.js +31 -0
  44. package/dist/esm/src/user-modules/message.js.map +1 -1
  45. package/dist/esm/src/user-modules/room.d.ts +3 -1
  46. package/dist/esm/src/user-modules/room.d.ts.map +1 -1
  47. package/dist/esm/src/user-modules/room.js +21 -3
  48. package/dist/esm/src/user-modules/room.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/package-json.ts +4 -4
  51. package/src/sayable/deliver-sayable.ts +6 -2
  52. package/src/sayable/mod.ts +4 -0
  53. package/src/sayable/types.ts +21 -2
  54. package/src/user-modules/contact.ts +8 -1
  55. package/src/user-modules/message.ts +39 -0
  56. package/src/user-modules/room.ts +32 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juzi/wechaty",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Wechaty is a RPA SDK for Chatbot Makers.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -109,8 +109,8 @@
109
109
  },
110
110
  "homepage": "https://github.com/wechaty/",
111
111
  "dependencies": {
112
- "@juzi/wechaty-puppet": "1.0.1",
113
- "@juzi/wechaty-puppet-service": "1.0.4",
112
+ "@juzi/wechaty-puppet": "1.0.2",
113
+ "@juzi/wechaty-puppet-service": "1.0.6",
114
114
  "clone-class": "^1.1.1",
115
115
  "cmd-ts": "^0.10.0",
116
116
  "cockatiel": "^2.0.2",
@@ -4,10 +4,10 @@
4
4
  */
5
5
  import type { PackageJsonWechaty } from './config'
6
6
 
7
- export const GIT_COMMIT_HASH: string = 'dd3d54130e20590b2d18801e099a0adaa7521176'
7
+ export const GIT_COMMIT_HASH: string = '531918e9b8f05a17b7442054cc26817ea0d187bb'
8
8
  export const packageJson: PackageJsonWechaty = {
9
9
  "name": "@juzi/wechaty",
10
- "version": "1.0.4",
10
+ "version": "1.0.5",
11
11
  "description": "Wechaty is a RPA SDK for Chatbot Makers.",
12
12
  "type": "module",
13
13
  "exports": {
@@ -116,8 +116,8 @@ export const packageJson: PackageJsonWechaty = {
116
116
  },
117
117
  "homepage": "https://github.com/wechaty/",
118
118
  "dependencies": {
119
- "@juzi/wechaty-puppet": "1.0.1",
120
- "@juzi/wechaty-puppet-service": "1.0.4",
119
+ "@juzi/wechaty-puppet": "1.0.2",
120
+ "@juzi/wechaty-puppet-service": "1.0.6",
121
121
  "clone-class": "^1.1.1",
122
122
  "cmd-ts": "^0.10.0",
123
123
  "cockatiel": "^2.0.2",
@@ -12,12 +12,12 @@ import {
12
12
  ChannelImpl,
13
13
  } from '../user-modules/mod.js'
14
14
 
15
- import type { Sayable } from './types.js'
15
+ import type { Sayable, SayOptionsObject } from './types.js'
16
16
 
17
17
  /**
18
18
  * TODO: add unit test to ensure the interface validation code works
19
19
  */
20
- const deliverSayableConversationPuppet = (puppet: PUPPET.impls.PuppetInterface) => (conversationId: string) => async (sayable: Sayable) => {
20
+ const deliverSayableConversationPuppet = (puppet: PUPPET.impls.PuppetInterface) => (conversationId: string) => async (sayable: Sayable, options?: SayOptionsObject) => {
21
21
  let msgId: string | void
22
22
 
23
23
  if (typeof sayable === 'number') {
@@ -28,6 +28,10 @@ const deliverSayableConversationPuppet = (puppet: PUPPET.impls.PuppetInterface)
28
28
  return puppet.messageSendText(
29
29
  conversationId,
30
30
  sayable,
31
+ {
32
+ mentionIdList: options?.mentionList?.map(c => c.id),
33
+ quoteId: options?.quoteMessage?.id,
34
+ },
31
35
  )
32
36
  }
33
37
 
@@ -1,6 +1,8 @@
1
1
  import type {
2
2
  SayableSayer,
3
3
  Sayable,
4
+ SayOptions,
5
+ SayOptionsObject,
4
6
  } from './types.js'
5
7
  import {
6
8
  messageToSayable,
@@ -18,6 +20,8 @@ import {
18
20
  export type {
19
21
  Sayable,
20
22
  SayableSayer,
23
+ SayOptions,
24
+ SayOptionsObject,
21
25
  }
22
26
  export {
23
27
  messageToSayable,
@@ -21,7 +21,7 @@ import type {
21
21
  FileBoxInterface,
22
22
  } from 'file-box'
23
23
 
24
- import type {
24
+ import {
25
25
  ContactInterface,
26
26
  DelayInterface,
27
27
  LocationInterface,
@@ -30,6 +30,8 @@ import type {
30
30
  PostInterface,
31
31
  UrlLinkInterface,
32
32
  ChannelInterface,
33
+ ContactImpl,
34
+ MessageImpl,
33
35
  } from '../user-modules/mod.js'
34
36
 
35
37
  import type {
@@ -54,11 +56,28 @@ interface SayableSayer {
54
56
  wechaty : WechatyInterface,
55
57
  say (
56
58
  sayable : Sayable,
57
- replyTo? : ContactInterface | ContactInterface[]
59
+ options? : SayOptions,
58
60
  ): Promise<void | MessageInterface>
59
61
  }
60
62
 
63
+ interface SayOptionsObject {
64
+ mentionList?: ContactInterface[],
65
+ quoteMessage?: MessageInterface,
66
+ }
67
+
68
+ export const isSayOptionsObject = (target: any) => {
69
+ return (typeof target === 'object'
70
+ && ((target.mentionList && target.mentionList.every((c: any) => ContactImpl.valid(c)))
71
+ || (target.quoteMessage && MessageImpl.valid(target.quoteMessage))
72
+ )
73
+ )
74
+ }
75
+
76
+ type SayOptions = ContactInterface | ContactInterface[] | SayOptionsObject
77
+
61
78
  export type {
62
79
  SayableSayer,
63
80
  Sayable,
81
+ SayOptions,
82
+ SayOptionsObject,
64
83
  }
@@ -45,6 +45,7 @@ import {
45
45
  import type {
46
46
  SayableSayer,
47
47
  Sayable,
48
+ SayOptionsObject,
48
49
  } from '../sayable/mod.js'
49
50
  import { stringifyFilter } from '../helper-functions/stringify-filter.js'
50
51
 
@@ -332,10 +333,16 @@ class ContactMixin extends MixinBase implements SayableSayer {
332
333
  */
333
334
  async say (
334
335
  sayable: Sayable,
336
+ options?: SayOptionsObject,
335
337
  ): Promise<void | MessageInterface> {
336
338
  log.verbose('Contact', 'say(%s)', sayable)
337
339
 
338
- const msgId = await deliverSayableConversationPuppet(this.wechaty.puppet)(this.id)(sayable)
340
+ if (options?.mentionList) {
341
+ log.warn('Contact', 'you cannot mention someone in private conversation!')
342
+ delete options.mentionList
343
+ }
344
+
345
+ const msgId = await deliverSayableConversationPuppet(this.wechaty.puppet)(this.id)(sayable, options)
339
346
 
340
347
  if (msgId) {
341
348
  const msg = await this.wechaty.Message.find({ id: msgId })
@@ -560,6 +560,32 @@ class MessageMixin extends MixinBase implements SayableSayer {
560
560
  }
561
561
  }
562
562
 
563
+ /**
564
+ * Reply a message while quoting the original one
565
+ * @param text
566
+ * @param mentionIdList
567
+ */
568
+ async reply (
569
+ text: string,
570
+ mentionList?: ContactInterface[],
571
+ ): Promise<void | MessageInterface> {
572
+ log.verbose('Message', 'say(%s)', text)
573
+
574
+ const talker = this.talker()
575
+ const room = this.room()
576
+
577
+ if (room) {
578
+ return room.say(text, {
579
+ mentionList,
580
+ quoteMessage: this,
581
+ })
582
+ } else {
583
+ return talker.say(text, {
584
+ quoteMessage: this,
585
+ })
586
+ }
587
+ }
588
+
563
589
  /**
564
590
  * Recall a message.
565
591
  * > Tips:
@@ -1100,6 +1126,19 @@ class MessageMixin extends MixinBase implements SayableSayer {
1100
1126
  return messageToSayable(this)
1101
1127
  }
1102
1128
 
1129
+ async getQuotedMessage (): Promise<undefined | MessageInterface> {
1130
+ log.verbose('Message', 'getQuotedMessage()')
1131
+ if (!this.payload) {
1132
+ throw new Error('no payload')
1133
+ }
1134
+
1135
+ if (!this.payload.quoteId) {
1136
+ throw new Error('this message did not quote another message')
1137
+ }
1138
+
1139
+ return this.wechaty.Message.find({ id: this.payload.quoteId })
1140
+ }
1141
+
1103
1142
  }
1104
1143
 
1105
1144
  class MessageImplBase extends validationMixin(MessageMixin)<MessageImplInterface>() {}
@@ -46,7 +46,7 @@ import {
46
46
  validationMixin,
47
47
  } from '../user-mixins/mod.js'
48
48
  import {
49
- deliverSayableConversationPuppet,
49
+ deliverSayableConversationPuppet, SayOptions, SayOptionsObject,
50
50
  } from '../sayable/mod.js'
51
51
  import type {
52
52
  SayableSayer,
@@ -61,6 +61,7 @@ import {
61
61
  import type {
62
62
  MessageInterface,
63
63
  } from './message.js'
64
+ import { isSayOptionsObject } from '../sayable/types.js'
64
65
 
65
66
  const MixinBase = wechatifyMixin(
66
67
  poolifyMixin(
@@ -355,7 +356,8 @@ class RoomMixin extends MixinBase implements SayableSayer {
355
356
  }
356
357
 
357
358
  say (sayable: Sayable) : Promise<void | MessageInterface>
358
- say (text: string, ...mentionList: ContactInterface[]) : Promise<void | MessageInterface>
359
+ say (text: string, options?: SayOptions): Promise<void | MessageInterface>
360
+ say (text: string, ...options: SayOptions[]): Promise<void | MessageInterface>
359
361
  say (textList: TemplateStringsArray, ...varList: any[]) : Promise<void | MessageInterface>
360
362
 
361
363
  // Huan(202006): allow fall down to the defination to get more flexibility.
@@ -464,15 +466,23 @@ class RoomMixin extends MixinBase implements SayableSayer {
464
466
  * 1. string
465
467
  */
466
468
  let mentionList: ContactInterface[] = []
469
+ let quoteMessage: MessageInterface | undefined
470
+ let options: SayOptionsObject
467
471
 
468
472
  if (varList.length > 0) {
469
- const allIsContact = varList.every(c => ContactImpl.valid(c))
473
+ if (isSayOptionsObject(varList[0])) {
474
+ options = varList[0] as SayOptionsObject
475
+ mentionList = options.mentionList || []
476
+ quoteMessage = options.quoteMessage
477
+ } else {
478
+ mentionList = varList as ContactInterface[]
479
+ }
480
+
481
+ const allIsContact = mentionList.every(c => ContactImpl.valid(c))
470
482
  if (!allIsContact) {
471
483
  throw new Error('mentionList must be contact when not using TemplateStringsArray function call.')
472
484
  }
473
485
 
474
- mentionList = [...varList as any]
475
-
476
486
  const AT_SEPARATOR = FOUR_PER_EM_SPACE
477
487
  const mentionAlias = await Promise.all(mentionList.map(async contact =>
478
488
  '@' + (await this.alias(contact) || contact.name()),
@@ -487,11 +497,23 @@ class RoomMixin extends MixinBase implements SayableSayer {
487
497
  // contactId : (mentionList.length && mentionList[0].id) || undefined,
488
498
  // roomId : this.id,
489
499
  // }
490
- msgId = await this.wechaty.puppet.messageSendText(
491
- this.id,
492
- text,
493
- mentionList.map(c => c.id),
494
- )
500
+ if (quoteMessage) {
501
+ msgId = await this.wechaty.puppet.messageSendText(
502
+ this.id,
503
+ text,
504
+ {
505
+ mentionIdList: mentionList.map(c => c.id),
506
+ quoteId: quoteMessage.id,
507
+ },
508
+ )
509
+ } else {
510
+ msgId = await this.wechaty.puppet.messageSendText(
511
+ this.id,
512
+ text,
513
+ mentionList.map(c => c.id),
514
+ )
515
+ }
516
+
495
517
  } else {
496
518
  msgId = await deliverSayableConversationPuppet(this.wechaty.puppet)(this.id)(sayable)
497
519
  }