-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
message-to-sayable.ts
57 lines (44 loc) · 1.31 KB
/
message-to-sayable.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
import * as PUPPET from 'wechaty-puppet'
import { log } from 'wechaty-puppet'
import type {
MessageInterface,
} from '../user-modules/mod.js'
import type { Sayable } from './types.js'
async function messageToSayable (
message: MessageInterface,
): Promise<undefined | Sayable> {
log.verbose('Wechaty', 'toSayable(%s)', message)
const type = message.type()
switch (type) {
case PUPPET.types.Message.Text:
return message.text()
case PUPPET.types.Message.Image:
case PUPPET.types.Message.Attachment:
case PUPPET.types.Message.Audio:
case PUPPET.types.Message.Video:
case PUPPET.types.Message.Emoticon:
return message.toFileBox()
case PUPPET.types.Message.Contact:
return message.toContact()
case PUPPET.types.Message.Url:
return message.toUrlLink()
case PUPPET.types.Message.MiniProgram:
return message.toMiniProgram()
case PUPPET.types.Message.Location:
return message.toLocation()
case PUPPET.types.Message.Post:
return message.toPost()
default:
log.warn('Wechaty',
'toSayable() can not convert not re-sayable type: %s(%s) for %s\n%s',
PUPPET.types.Message[type],
type,
message,
new Error().stack,
)
return undefined
}
}
export {
messageToSayable,
}