@juzi/wechaty 1.0.149 → 1.0.150
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.
- package/dist/cjs/src/mods/impls.d.ts +3 -3
- package/dist/cjs/src/mods/impls.d.ts.map +1 -1
- package/dist/cjs/src/mods/impls.js +2 -1
- package/dist/cjs/src/mods/impls.js.map +1 -1
- package/dist/cjs/src/mods/users.d.ts +1 -1
- package/dist/cjs/src/mods/users.d.ts.map +1 -1
- package/dist/cjs/src/package-json.js +4 -4
- package/dist/cjs/src/user-modules/message.d.ts +15 -0
- package/dist/cjs/src/user-modules/message.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/message.js +20 -0
- package/dist/cjs/src/user-modules/message.js.map +1 -1
- package/dist/cjs/src/user-modules/mod.d.ts +4 -3
- package/dist/cjs/src/user-modules/mod.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/mod.js +3 -1
- package/dist/cjs/src/user-modules/mod.js.map +1 -1
- package/dist/cjs/src/user-modules/voice.d.ts +69 -0
- package/dist/cjs/src/user-modules/voice.d.ts.map +1 -0
- package/dist/cjs/src/user-modules/voice.js +64 -0
- package/dist/cjs/src/user-modules/voice.js.map +1 -0
- package/dist/cjs/src/wechaty/wechaty-base.d.ts +10 -0
- package/dist/cjs/src/wechaty/wechaty-base.d.ts.map +1 -1
- package/dist/cjs/src/wechaty/wechaty-impl.spec.js +25 -23
- package/dist/cjs/src/wechaty/wechaty-impl.spec.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/login-mixin.d.ts +12 -0
- package/dist/cjs/src/wechaty-mixins/login-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts +6 -0
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/plugin-mixin.d.ts +8 -12
- package/dist/cjs/src/wechaty-mixins/plugin-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts +4 -0
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +4 -2
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.js +3 -0
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.js.map +1 -1
- package/dist/esm/src/mods/impls.d.ts +3 -3
- package/dist/esm/src/mods/impls.d.ts.map +1 -1
- package/dist/esm/src/mods/impls.js +1 -1
- package/dist/esm/src/mods/impls.js.map +1 -1
- package/dist/esm/src/mods/users.d.ts +1 -1
- package/dist/esm/src/mods/users.d.ts.map +1 -1
- package/dist/esm/src/package-json.js +4 -4
- package/dist/esm/src/user-modules/message.d.ts +15 -0
- package/dist/esm/src/user-modules/message.d.ts.map +1 -1
- package/dist/esm/src/user-modules/message.js +20 -0
- package/dist/esm/src/user-modules/message.js.map +1 -1
- package/dist/esm/src/user-modules/mod.d.ts +4 -3
- package/dist/esm/src/user-modules/mod.d.ts.map +1 -1
- package/dist/esm/src/user-modules/mod.js +2 -1
- package/dist/esm/src/user-modules/mod.js.map +1 -1
- package/dist/esm/src/user-modules/voice.d.ts +69 -0
- package/dist/esm/src/user-modules/voice.d.ts.map +1 -0
- package/dist/esm/src/user-modules/voice.js +61 -0
- package/dist/esm/src/user-modules/voice.js.map +1 -0
- package/dist/esm/src/wechaty/wechaty-base.d.ts +10 -0
- package/dist/esm/src/wechaty/wechaty-base.d.ts.map +1 -1
- package/dist/esm/src/wechaty/wechaty-impl.spec.js +25 -23
- package/dist/esm/src/wechaty/wechaty-impl.spec.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/login-mixin.d.ts +12 -0
- package/dist/esm/src/wechaty-mixins/login-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts +6 -0
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/plugin-mixin.d.ts +8 -12
- package/dist/esm/src/wechaty-mixins/plugin-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts +4 -0
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +4 -2
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.js +4 -1
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.js.map +1 -1
- package/package.json +3 -3
- package/src/mods/impls.ts +3 -0
- package/src/mods/users.ts +1 -0
- package/src/package-json.ts +4 -4
- package/src/user-modules/message.ts +24 -0
- package/src/user-modules/mod.ts +8 -0
- package/src/user-modules/voice.ts +104 -0
- package/src/wechaty/wechaty-impl.spec.ts +3 -0
- package/src/wechaty-mixins/wechatify-user-module-mixin.ts +6 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
|
|
5
|
+
* Wechaty Contributors <https://github.com/wechaty>.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
import type {
|
|
21
|
+
FileBoxInterface,
|
|
22
|
+
} from 'file-box'
|
|
23
|
+
import type { Constructor } from 'clone-class'
|
|
24
|
+
import { validationMixin } from '../user-mixins/validation.js'
|
|
25
|
+
import { log } from '../config.js'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
wechatifyMixinBase,
|
|
29
|
+
} from '../user-mixins/wechatify.js'
|
|
30
|
+
|
|
31
|
+
class VoiceMixin extends wechatifyMixinBase() {
|
|
32
|
+
|
|
33
|
+
static create (id: string): VoiceInterface {
|
|
34
|
+
log.verbose('Voice', 'static create(%s)', id)
|
|
35
|
+
|
|
36
|
+
const voice = new this(id)
|
|
37
|
+
return voice
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor (
|
|
41
|
+
public id: string,
|
|
42
|
+
) {
|
|
43
|
+
super()
|
|
44
|
+
log.verbose('Voice', 'constructor(%s)', id)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the voice file (FileBox) via the puppet's dedicated `messageVoice` RPC.
|
|
49
|
+
*
|
|
50
|
+
* Falls back to the generic `messageFile` when the puppet does not implement
|
|
51
|
+
* `messageVoice` (old puppet without the new RPC → rejection), keeping the
|
|
52
|
+
* behaviour compatible with the legacy "voice file via messageFile" path.
|
|
53
|
+
*/
|
|
54
|
+
async file (): Promise<FileBoxInterface> {
|
|
55
|
+
log.verbose('Voice', 'file() for id: "%s"', this.id)
|
|
56
|
+
try {
|
|
57
|
+
const fileBox = await this.wechaty.puppet.messageVoice(this.id)
|
|
58
|
+
return fileBox
|
|
59
|
+
} catch (e) {
|
|
60
|
+
log.verbose('Voice', 'file() messageVoice() failed, fallback to messageFile(): %s', (e as Error).message)
|
|
61
|
+
const fileBox = await this.wechaty.puppet.messageFile(this.id)
|
|
62
|
+
return fileBox
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the voice-to-text (ASR) result via the puppet's dedicated
|
|
68
|
+
* `messageVoiceText` RPC. Returns a discriminated result so the bot can tell
|
|
69
|
+
* "confirmed no speech" (`noSpeech=true`) from "normal transcription".
|
|
70
|
+
*
|
|
71
|
+
* Falls back to reading the legacy `messagePayload().text` when the puppet
|
|
72
|
+
* does not implement `messageVoiceText` (old puppet without the new RPC →
|
|
73
|
+
* rejection). Old puppets put the ASR result into `payload.text`, so this
|
|
74
|
+
* keeps the behaviour compatible; `noSpeech` is `false` in the fallback.
|
|
75
|
+
*/
|
|
76
|
+
async text (): Promise<{ text: string; noSpeech: boolean }> {
|
|
77
|
+
log.verbose('Voice', 'text() for id: "%s"', this.id)
|
|
78
|
+
try {
|
|
79
|
+
const payload = await this.wechaty.puppet.messageVoiceText(this.id)
|
|
80
|
+
return payload
|
|
81
|
+
} catch (e) {
|
|
82
|
+
log.verbose('Voice', 'text() messageVoiceText() failed, fallback to messagePayload().text: %s', (e as Error).message)
|
|
83
|
+
const payload = await this.wechaty.puppet.messagePayload(this.id)
|
|
84
|
+
return { text: payload.text || '', noSpeech: false }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class VoiceImpl extends validationMixin(VoiceMixin)<VoiceInterface>() {}
|
|
91
|
+
interface VoiceInterface extends VoiceImpl { }
|
|
92
|
+
|
|
93
|
+
type VoiceConstructor = Constructor<
|
|
94
|
+
VoiceInterface,
|
|
95
|
+
typeof VoiceImpl
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
export type {
|
|
99
|
+
VoiceConstructor,
|
|
100
|
+
VoiceInterface,
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
VoiceImpl,
|
|
104
|
+
}
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
ContactConstructor,
|
|
10
10
|
FriendshipConstructor,
|
|
11
11
|
ImageConstructor,
|
|
12
|
+
VoiceConstructor,
|
|
12
13
|
LocationConstructor,
|
|
13
14
|
MessageConstructor,
|
|
14
15
|
MiniProgramConstructor,
|
|
@@ -51,6 +52,7 @@ test('Wechaty interface', async t => {
|
|
|
51
52
|
Delay : DelayConstructor
|
|
52
53
|
Friendship : FriendshipConstructor
|
|
53
54
|
Image : ImageConstructor
|
|
55
|
+
Voice : VoiceConstructor
|
|
54
56
|
Location : LocationConstructor
|
|
55
57
|
Message : MessageConstructor
|
|
56
58
|
MiniProgram : MiniProgramConstructor
|
|
@@ -82,6 +84,7 @@ test('Wechaty interface', async t => {
|
|
|
82
84
|
= this.Delay
|
|
83
85
|
= this.Friendship
|
|
84
86
|
= this.Image
|
|
87
|
+
= this.Voice
|
|
85
88
|
= this.Location
|
|
86
89
|
= this.Message
|
|
87
90
|
= this.MiniProgram
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
DelayImpl,
|
|
8
8
|
FriendshipImpl,
|
|
9
9
|
ImageImpl,
|
|
10
|
+
VoiceImpl,
|
|
10
11
|
LocationImpl,
|
|
11
12
|
MessageImpl,
|
|
12
13
|
MiniProgramImpl,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
DelayConstructor,
|
|
36
37
|
FriendshipConstructor,
|
|
37
38
|
ImageConstructor,
|
|
39
|
+
VoiceConstructor,
|
|
38
40
|
LocationConstructor,
|
|
39
41
|
MessageConstructor,
|
|
40
42
|
MiniProgramConstructor,
|
|
@@ -79,6 +81,7 @@ const wechatifyUserModuleMixin = <MixinBase extends typeof WechatySkeleton> (mix
|
|
|
79
81
|
__wechatifiedDelay? : DelayConstructor
|
|
80
82
|
__wechatifiedFriendship? : FriendshipConstructor
|
|
81
83
|
__wechatifiedImage? : ImageConstructor
|
|
84
|
+
__wechatifiedVoice? : VoiceConstructor
|
|
82
85
|
__wechatifiedLocation? : LocationConstructor
|
|
83
86
|
__wechatifiedMessage? : MessageConstructor
|
|
84
87
|
__wechatifiedMiniProgram? : MiniProgramConstructor
|
|
@@ -107,6 +110,7 @@ const wechatifyUserModuleMixin = <MixinBase extends typeof WechatySkeleton> (mix
|
|
|
107
110
|
get Delay () : DelayConstructor { return guardWechatify(this.__wechatifiedDelay) }
|
|
108
111
|
get Friendship () : FriendshipConstructor { return guardWechatify(this.__wechatifiedFriendship) }
|
|
109
112
|
get Image () : ImageConstructor { return guardWechatify(this.__wechatifiedImage) }
|
|
113
|
+
get Voice () : VoiceConstructor { return guardWechatify(this.__wechatifiedVoice) }
|
|
110
114
|
get Location () : LocationConstructor { return guardWechatify(this.__wechatifiedLocation) }
|
|
111
115
|
get Message () : MessageConstructor { return guardWechatify(this.__wechatifiedMessage) }
|
|
112
116
|
get MiniProgram () : MiniProgramConstructor { return guardWechatify(this.__wechatifiedMiniProgram) }
|
|
@@ -155,6 +159,7 @@ const wechatifyUserModuleMixin = <MixinBase extends typeof WechatySkeleton> (mix
|
|
|
155
159
|
this.__wechatifiedDelay = wechatifyUserModule(DelayImpl)(this as any)
|
|
156
160
|
this.__wechatifiedFriendship = wechatifyUserModule(FriendshipImpl)(this as any)
|
|
157
161
|
this.__wechatifiedImage = wechatifyUserModule(ImageImpl)(this as any)
|
|
162
|
+
this.__wechatifiedVoice = wechatifyUserModule(VoiceImpl)(this as any)
|
|
158
163
|
this.__wechatifiedLocation = wechatifyUserModule(LocationImpl)(this as any)
|
|
159
164
|
this.__wechatifiedMessage = wechatifyUserModule(MessageImpl)(this as any)
|
|
160
165
|
this.__wechatifiedMiniProgram = wechatifyUserModule(MiniProgramImpl)(this as any)
|
|
@@ -204,6 +209,7 @@ type ProtectedPropertyWechatifyUserModuleMixin =
|
|
|
204
209
|
| '__wechatifiedDelay'
|
|
205
210
|
| '__wechatifiedFriendship'
|
|
206
211
|
| '__wechatifiedImage'
|
|
212
|
+
| '__wechatifiedVoice'
|
|
207
213
|
| '__wechatifiedLocation'
|
|
208
214
|
| '__wechatifiedMessage'
|
|
209
215
|
| '__wechatifiedMiniProgram'
|