-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
message.ts
871 lines (778 loc) · 23.5 KB
/
message.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
/**
* Wechaty - https://github.com/chatie/wechaty
*
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @ignore
*/
import {
instanceToClass,
} from 'clone-class'
import {
FileBox,
} from 'file-box'
import {
MessagePayload,
MessageQueryFilter,
MessageType,
} from 'wechaty-puppet'
import {
Accessory,
} from '../accessory'
import {
FOUR_PER_EM_SPACE,
log,
Raven,
} from '../config'
import {
Sayable,
} from '../types'
import {
Contact,
} from './contact'
import {
Room,
} from './room'
import {
UrlLink,
} from './url-link'
/**
* All wechat messages will be encapsulated as a Message.
*
* [Examples/Ding-Dong-Bot]{@link https://github.com/Chatie/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/ding-dong-bot.ts}
*/
export class Message extends Accessory implements Sayable {
/**
*
* Static Properties
*
*/
/**
* @private
*/
// tslint:disable-next-line:variable-name
public static readonly Type = MessageType
/**
* @ignore
* @todo add function
*/
public static async find<T extends typeof Message> (
this: T,
query : string | MessageQueryFilter,
): Promise<T['prototype'] | null> {
log.verbose('Message', 'find(%s)', JSON.stringify(query))
if (typeof query === 'string') {
query = { text: query }
}
const messageList = await this.findAll(query)
if (messageList.length < 1) {
return null
}
if (messageList.length > 1) {
log.warn('Message', 'findAll() got more than one(%d) result', messageList.length)
}
return messageList[0]
}
/**
* @ignore
* @todo add function
*/
public static async findAll<T extends typeof Message> (
this : T,
query?: MessageQueryFilter,
): Promise<Array<T['prototype']>> {
log.verbose('Message', 'findAll(%s)', JSON.stringify(query))
try {
const MessageIdList = await this.puppet.messageSearch(query)
const messageList = MessageIdList.map(id => this.load(id))
await Promise.all(
messageList.map(
message => {
try {
return message.ready()
} catch (e) {
return {} as any
}
},
),
)
return messageList.filter(message => !!message.id)
} catch (e) {
log.verbose('Message', 'findAll() rejected: %s', e.message)
console.error(e)
Raven.captureException(e)
return [] // fail safe
}
}
/**
* Create a Mobile Terminated Message
* @ignore
* "mobile originated" or "mobile terminated"
* https://www.tatango.com/resources/video-lessons/video-mo-mt-sms-messaging/
*/
public static load (id: string): Message {
log.verbose('Message', 'static load(%s)', id)
/**
* Must NOT use `Message` at here
* MUST use `this` at here
*
* because the class will be `cloneClass`-ed
*/
const msg = new this(id)
return msg
}
/**
* TODO: rename create to load ??? Huan 201806
* @deprecated: use load() instead
* @private
*/
public static create (id: string): Message {
log.warn('Message', 'static create(%s) DEPRECATED. Use load() instead', id)
return this.load(id)
}
/**
*
* Instance Properties
* @hidden
*
*/
protected payload?: MessagePayload
/**
* @private
*/
constructor (
public readonly id: string,
) {
super()
log.verbose('Message', 'constructor(%s) for class %s',
id || '',
this.constructor.name,
)
// tslint:disable-next-line:variable-name
const MyClass = instanceToClass(this, Message)
if (MyClass === Message) {
throw new Error('Message class can not be instanciated directly! See: https://github.com/Chatie/wechaty/issues/1217')
}
if (!this.puppet) {
throw new Error('Message class can not be instanciated without a puppet!')
}
}
/**
* @private
*/
public toString () {
if (!this.payload) {
return this.constructor.name
}
const msgStrList = [
'Message',
`#${MessageType[this.type()]}`,
'(',
this.room()
? '👥' + this.room()
: '',
this.from()
? '🗣' + this.from()
: '',
this.to()
? '👤' + this.to()
: '',
')',
]
if ( this.type() === Message.Type.Text
|| this.type() === Message.Type.Unknown
) {
msgStrList.push(`<${this.text().substr(0, 70)}>`)
} else {
log.silly('Message', 'toString() for message type: %s(%s)', Message.Type[this.type()], this.type())
if (!this.payload) {
throw new Error('no payload')
}
// const filename = this.puppet.messagefile payload.filename
// if (!filename) {
// throw new Error(
// 'no file for message id: ' + this.id
// + ' with type: ' + Message.Type[this.payload.type]
// + '(' + this.payload.type + ')',
// )
// }
// msgStrList.push(`<${filename || 'unknown file name'}>`)
}
return msgStrList.join('')
}
/**
* Get the sender from a message.
* @returns {Contact}
* @example
* const bot = new Wechaty()
* bot
* .on('message', async m => {
* const contact = msg.from()
* const text = msg.text()
* const room = msg.room()
* if (room) {
* const topic = await room.topic()
* console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`)
* } else {
* console.log(`Contact: ${contact.name()} Text: ${text}`)
* }
* })
* .start()
*/
public from (): null | Contact {
if (!this.payload) {
throw new Error('no payload')
}
// if (contact) {
// this.payload.from = contact
// return
// }
const fromId = this.payload.fromId
if (!fromId) {
return null
}
const from = this.wechaty.Contact.load(fromId)
return from
}
/**
* Get the destination of the message
* Message.to() will return null if a message is in a room, use Message.room() to get the room.
* @returns {(Contact|null)}
*/
public to (): null | Contact {
if (!this.payload) {
throw new Error('no payload')
}
const toId = this.payload.toId
if (!toId) {
return null
}
const to = this.wechaty.Contact.load(toId)
return to
}
/**
* Get the room from the message.
* If the message is not in a room, then will return `null`
*
* @returns {(Room | null)}
* @example
* const bot = new Wechaty()
* bot
* .on('message', async m => {
* const contact = msg.from()
* const text = msg.text()
* const room = msg.room()
* if (room) {
* const topic = await room.topic()
* console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`)
* } else {
* console.log(`Contact: ${contact.name()} Text: ${text}`)
* }
* })
* .start()
*/
public room (): null | Room {
if (!this.payload) {
throw new Error('no payload')
}
const roomId = this.payload.roomId
if (!roomId) {
return null
}
const room = this.wechaty.Room.load(roomId)
return room
}
/**
* @description
* use {@link Message#text} instead
*
* @deprecated
*/
public content (): string {
log.warn('Message', 'content() DEPRECATED. use text() instead.')
return this.text()
}
/**
* Get the text content of the message
*
* @returns {string}
* @example
* const bot = new Wechaty()
* bot
* .on('message', async m => {
* const contact = msg.from()
* const text = msg.text()
* const room = msg.room()
* if (room) {
* const topic = await room.topic()
* console.log(`Room: ${topic} Contact: ${contact.name()} Text: ${text}`)
* } else {
* console.log(`Contact: ${contact.name()} Text: ${text}`)
* }
* })
* .start()
*/
public text (): string {
if (!this.payload) {
throw new Error('no payload')
}
return this.payload.text || ''
}
public async say (text: string, mention?: Contact | Contact[]) : Promise<void>
public async say (contact: Contact) : Promise<void>
public async say (file: FileBox) : Promise<void>
public async say (url: UrlLink) : Promise<void>
public async say (...args: never[]): Promise<never>
/**
* Reply a Text or Media File message to the sender.
* > Tips:
* This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/Chatie/wechaty/wiki/Puppet#3-puppet-compatible-table)
*
* @see {@link https://github.com/Chatie/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/ding-dong-bot.ts|Examples/ding-dong-bot}
* @param {(string | Contact | FileBox)} textOrContactOrFile
* send text, Contact, or file to bot. </br>
* You can use {@link https://www.npmjs.com/package/file-box|FileBox} to send file
* @param {(Contact|Contact[])} [mention]
* If this is a room message, when you set mention param, you can `@` Contact in the room.
* @returns {Promise<void>}
*
* @example
* import { FileBox } from 'file-box'
* const bot = new Wechaty()
* bot
* .on('message', async m => {
*
* // 1. send Image
*
* if (/^ding$/i.test(m.text())) {
* const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
* await msg.say(fileBox)
* }
*
* // 2. send Text
*
* if (/^dong$/i.test(m.text())) {
* await msg.say('dingdingding')
* }
*
* // 3. send Contact
*
* if (/^lijiarui$/i.test(m.text())) {
* const contactCard = await bot.Contact.find({name: 'lijiarui'})
* if (!contactCard) {
* console.log('not found')
* return
* }
* await msg.say(contactCard)
* }
*
* })
* .start()
*/
public async say (
textOrContactOrFileOrUrl : string | Contact | FileBox | UrlLink,
mention? : Contact | Contact[],
): Promise<void> {
log.verbose('Message', 'say(%s%s)',
textOrContactOrFileOrUrl,
mention
? ', ' + mention
: '',
)
// const user = this.puppet.userSelf()
const from = this.from()
// const to = this.to()
const room = this.room()
const mentionList = mention
? Array.isArray(mention)
? mention
: [mention]
: []
if (typeof textOrContactOrFileOrUrl === 'string') {
await this.sayText(
textOrContactOrFileOrUrl,
from || undefined,
room || undefined,
mentionList,
)
} else if (textOrContactOrFileOrUrl instanceof Contact) {
/**
* Contact Card
*/
await this.puppet.messageSendContact({
contactId : from && from.id || undefined,
roomId : room && room.id || undefined,
}, textOrContactOrFileOrUrl.id)
} else if (textOrContactOrFileOrUrl instanceof FileBox) {
/**
* File Message
*/
await this.puppet.messageSendFile({
contactId : from && from.id || undefined,
roomId : room && room.id || undefined,
}, textOrContactOrFileOrUrl)
} else if (textOrContactOrFileOrUrl instanceof UrlLink) {
/**
* Link Message
*/
await this.puppet.messageSendUrl({
contactId : from && from.id || undefined,
roomId : room && room.id || undefined,
}, textOrContactOrFileOrUrl.payload)
} else {
throw new Error('unknown msg: ' + textOrContactOrFileOrUrl)
}
}
private async sayText (
text : string,
to? : Contact,
room? : Room,
mentionList? : Contact[],
): Promise<void> {
if (room && mentionList && mentionList.length > 0) {
/**
* 1 had mentioned someone
*/
const mentionContact = mentionList[0]
const textMentionList = mentionList.map(c => '@' + c.name()).join(' ')
await this.puppet.messageSendText({
contactId: mentionContact.id,
roomId: room.id,
}, textMentionList + ' ' + text)
} else {
/**
* 2 did not mention anyone
*/
await this.puppet.messageSendText({
contactId : to && to.id,
roomId : room && room.id,
}, text)
}
}
/**
* Get the type from the message.
* > Tips: MessageType is Enum here. </br>
* - MessageType.Unknown </br>
* - MessageType.Attachment </br>
* - MessageType.Audio </br>
* - MessageType.Contact </br>
* - MessageType.Emoticon </br>
* - MessageType.Image </br>
* - MessageType.Text </br>
* - MessageType.Video </br>
* - MessageType.Url </br>
* @returns {MessageType}
*
* @example
* const bot = new Wechaty()
* if (message.type() === bot.Message.Type.Text) {
* console.log('This is a text message')
* }
*/
public type (): MessageType {
if (!this.payload) {
throw new Error('no payload')
}
return this.payload.type || MessageType.Unknown
}
/**
* Check if a message is sent by self.
*
* @returns {boolean} - Return `true` for send from self, `false` for send from others.
* @example
* if (message.self()) {
* console.log('this message is sent by myself!')
* }
*/
public self (): boolean {
const userId = this.puppet.selfId()
const from = this.from()
return !!from && from.id === userId
}
/**
*
* Get message mentioned contactList.
*
* Message event table as follows
*
* | | Web | Mac PC Client | iOS Mobile | android Mobile |
* | :--- | :--: | :----: | :---: | :---: |
* | [You were mentioned] tip ([有人@我]的提示) | ✘ | √ | √ | √ |
* | Identify magic code (8197) by copy & paste in mobile | ✘ | √ | √ | ✘ |
* | Identify magic code (8197) by programming | ✘ | ✘ | ✘ | ✘ |
* | Identify two contacts with the same roomAlias by [You were mentioned] tip | ✘ | ✘ | √ | √ |
*
* @returns {Promise<Contact[]>} - Return message mentioned contactList
*
* @example
* const contactList = await message.mention()
* console.log(contactList)
*/
public async mention (): Promise<Contact[]> {
log.verbose('Message', 'mention()')
const room = this.room()
if (this.type() !== MessageType.Text || !room ) {
return []
}
// define magic code `8197` to identify @xxx
// const AT_SEPRATOR = String.fromCharCode(8197)
const AT_SEPRATOR = FOUR_PER_EM_SPACE
const atList = this.text().split(AT_SEPRATOR)
// console.log('atList: ', atList)
if (atList.length === 0) return []
// Using `filter(e => e.indexOf('@') > -1)` to filter the string without `@`
const rawMentionList = atList
.filter(str => str.includes('@'))
.map(str => multipleAt(str))
// convert 'hello@a@b@c' to [ 'c', 'b@c', 'a@b@c' ]
function multipleAt (str: string) {
str = str.replace(/^.*?@/, '@')
let name = ''
const nameList: string[] = []
str.split('@')
.filter(mentionName => !!mentionName)
.reverse()
.forEach(mentionName => {
// console.log('mentionName: ', mentionName)
name = mentionName + '@' + name
nameList.push(name.slice(0, -1)) // get rid of the `@` at beginning
})
return nameList
}
let mentionNameList: string[] = []
// Flatten Array
// see http://stackoverflow.com/a/10865042/1123955
mentionNameList = mentionNameList.concat.apply([], rawMentionList)
// filter blank string
mentionNameList = mentionNameList.filter(s => !!s)
log.verbose('Message', 'mention() text = "%s", mentionNameList = "%s"',
this.text(),
JSON.stringify(mentionNameList),
)
const contactListNested = await Promise.all(
mentionNameList.map(
name => room.memberAll(name),
),
)
let contactList: Contact[] = []
contactList = contactList.concat.apply([], contactListNested)
if (contactList.length === 0) {
log.silly('Message', `message.mention() can not found member using room.member() from mentionList, metion string: ${JSON.stringify(mentionNameList)}`)
}
return contactList
}
/**
* @description
* should use {@link Message#mention} instead
* @deprecated
* @private
*/
public async mentioned (): Promise<Contact[]> {
log.warn('Message', 'mentioned() DEPRECATED. use mention() instead.')
return this.mention()
}
/**
* Check if a message is mention self.
*
* @returns {Promise<boolean>} - Return `true` for mention me.
* @example
* if (await message.mentionSelf()) {
* console.log('this message were mentioned me! [You were mentioned] tip ([有人@我]的提示)')
* }
*/
public async mentionSelf (): Promise<boolean> {
const selfId = this.puppet.selfId()
const mentionList = await this.mention()
return mentionList.some(contact => contact.id === selfId)
}
/**
* @private
*/
public isReady (): boolean {
return !!this.payload
}
/**
* @private
*/
public async ready (): Promise<void> {
log.verbose('Message', 'ready()')
if (this.isReady()) {
return
}
this.payload = await this.puppet.messagePayload(this.id)
if (!this.payload) {
throw new Error('no payload')
}
const fromId = this.payload.fromId
const roomId = this.payload.roomId
const toId = this.payload.toId
if (fromId) {
await this.wechaty.Contact.load(fromId).ready()
}
if (roomId) {
await this.wechaty.Room.load(roomId).ready()
}
if (toId) {
await this.wechaty.Contact.load(toId).ready()
}
}
// case WebMsgType.APP:
// if (!this.rawObj) {
// throw new Error('no rawObj')
// }
// switch (this.typeApp()) {
// case WebAppMsgType.ATTACH:
// if (!this.rawObj.MMAppMsgDownloadUrl) {
// throw new Error('no MMAppMsgDownloadUrl')
// }
// // had set in Message
// // url = this.rawObj.MMAppMsgDownloadUrl
// break
// case WebAppMsgType.URL:
// case WebAppMsgType.READER_TYPE:
// if (!this.rawObj.Url) {
// throw new Error('no Url')
// }
// // had set in Message
// // url = this.rawObj.Url
// break
// default:
// const e = new Error('ready() unsupported typeApp(): ' + this.typeApp())
// log.warn('PuppeteerMessage', e.message)
// throw e
// }
// break
// case WebMsgType.TEXT:
// if (this.typeSub() === WebMsgType.LOCATION) {
// url = await puppet.bridge.getMsgPublicLinkImg(this.id)
// }
// break
/**
* Forward the received message.
*
* @param {(Sayable | Sayable[])} to Room or Contact
* The recipient of the message, the room, or the contact
* @returns {Promise<void>}
* @example
* const bot = new Wechaty()
* bot
* .on('message', async m => {
* const room = await bot.Room.find({topic: 'wechaty'})
* if (room) {
* await m.forward(room)
* console.log('forward this message to wechaty room!')
* }
* })
* .start()
*/
public async forward (to: Room | Contact): Promise<void> {
log.verbose('Message', 'forward(%s)', to)
let roomId
let contactId
if (to instanceof Room) {
roomId = to.id
} else if (to instanceof Contact) {
contactId = to.id
}
try {
await this.puppet.messageForward(
{
contactId,
roomId,
},
this.id,
)
} catch (e) {
log.error('Message', 'forward(%s) exception: %s', to, e)
throw e
}
}
/**
* @private
*/
public date (): Date {
if (!this.payload) {
throw new Error('no payload')
}
// convert the unit timestamp to milliseconds
// (from seconds to milliseconds)
return new Date(1000 * this.payload.timestamp)
}
/**
* Returns the message age in seconds. <br>
*
* For example, the message is sent at time `8:43:01`,
* and when we received it in Wechaty, the time is `8:43:15`,
* then the age() will return `8:43:15 - 8:43:01 = 14 (seconds)`
* @returns {number}
*/
public age (): number {
const ageMilliseconds = Date.now() - this.date().getTime()
const ageSeconds = Math.floor(ageMilliseconds / 1000)
return ageSeconds
}
/**
* @description
* use {@link Message#toFileBox} instead
* @deprecated
*/
public async file (): Promise<FileBox> {
log.warn('Message', 'file() DEPRECATED. use toFileBox() instead.')
return this.toFileBox()
}
/**
* Extract the Media File from the Message, and put it into the FileBox.
* > Tips:
* This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/Chatie/wechaty/wiki/Puppet#3-puppet-compatible-table)
*
* @returns {Promise<FileBox>}
*/
public async toFileBox (): Promise<FileBox> {
if (this.type() === Message.Type.Text) {
throw new Error('text message no file')
}
const fileBox = await this.puppet.messageFile(this.id)
return fileBox
}
/**
* Get Share Card of the Message
* Extract the Contact Card from the Message, and encapsulate it into Contact class
* > Tips:
* This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/Chatie/wechaty/wiki/Puppet#3-puppet-compatible-table)
* @returns {Promise<Contact>}
*/
public async toContact (): Promise<Contact> {
log.warn('Message', 'toContact() to be implemented')
if (this.type() === Message.Type.Contact) {
throw new Error('message not a ShareCard')
}
// TODO: return the ShareCard Contact
const contact = this.wechaty.userSelf()
return contact
}
public async toUrl (): Promise<UrlLink> {
log.verbose('Message', 'toUrl()')
if (!this.payload) {
throw new Error('no payload')
}
if (this.type() !== Message.Type.Url) {
throw new Error('message not a Url Link')
}
const urlPayload = await this.puppet.messageUrl(this.id)
if (!urlPayload) {
throw new Error(`no url payload for message ${this.id}`)
}
return new UrlLink(urlPayload)
}
}