@satorijs/adapter-lark 3.7.1 → 3.7.2
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/lib/index.cjs +31 -19
- package/lib/index.cjs.map +2 -2
- package/lib/types/api.d.ts +348 -52
- package/lib/types/internal.d.ts +6 -4
- package/package.json +1 -1
- package/src/message.ts +20 -17
- package/src/types/api.ts +349 -53
- package/src/types/internal.ts +17 -5
package/lib/types/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dict } from '@satorijs/core';
|
|
1
|
+
import { Dict, HTTP } from '@satorijs/core';
|
|
2
2
|
import { LarkBot } from '../bot';
|
|
3
3
|
export interface Internal {
|
|
4
4
|
}
|
|
@@ -8,11 +8,13 @@ export interface BaseResponse {
|
|
|
8
8
|
/** error message. would be 'success' if success. */
|
|
9
9
|
msg: string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
export interface InternalConfig {
|
|
12
|
+
multipart?: boolean;
|
|
13
|
+
noExtractData?: boolean;
|
|
14
|
+
}
|
|
12
15
|
export declare class Internal {
|
|
13
16
|
private bot;
|
|
14
17
|
constructor(bot: LarkBot);
|
|
15
18
|
private assertResponse;
|
|
16
|
-
static define(routes: Dict<Partial<Record<Method, string | string[]>>>,
|
|
19
|
+
static define(routes: Dict<Partial<Record<HTTP.Method, string | string[]>>>, options?: InternalConfig): void;
|
|
17
20
|
}
|
|
18
|
-
export {};
|
package/package.json
CHANGED
package/src/message.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, Dict, h, MessageEncoder } from '@satorijs/core'
|
|
2
2
|
import { LarkBot } from './bot'
|
|
3
|
-
import { Lark, MessageContent } from './types'
|
|
3
|
+
import { CreateImFileForm, Lark, MessageContent } from './types'
|
|
4
4
|
import { extractIdType } from './utils'
|
|
5
5
|
|
|
6
6
|
export class LarkMessageEncoder<C extends Context = Context> extends MessageEncoder<C, LarkBot<C>> {
|
|
@@ -93,40 +93,43 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
|
|
|
93
93
|
|
|
94
94
|
async createImage(url: string) {
|
|
95
95
|
const { filename, type, data } = await this.bot.assetsQuester.file(url)
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const { image_key } = await this.bot.internal.createImImage({
|
|
97
|
+
image_type: 'message',
|
|
98
|
+
image: new File([data], filename, { type }),
|
|
99
|
+
})
|
|
100
100
|
return image_key
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
async sendFile(_type: 'video' | 'audio' | 'file', attrs: any) {
|
|
104
104
|
const url = attrs.src || attrs.url
|
|
105
|
-
const payload = new FormData()
|
|
106
105
|
const { filename, type, data } = await this.bot.assetsQuester.file(url)
|
|
107
|
-
payload.append('file', new Blob([data], { type }), filename)
|
|
108
|
-
payload.append('file_name', filename)
|
|
109
|
-
|
|
110
|
-
if (attrs.duration) {
|
|
111
|
-
payload.append('duration', attrs.duration)
|
|
112
|
-
}
|
|
113
106
|
|
|
107
|
+
let file_type: CreateImFileForm['file_type']
|
|
114
108
|
if (_type === 'audio') {
|
|
115
109
|
// FIXME: only support opus
|
|
116
|
-
|
|
110
|
+
file_type = 'opus'
|
|
117
111
|
} else if (_type === 'video') {
|
|
118
112
|
// FIXME: only support mp4
|
|
119
|
-
|
|
113
|
+
file_type = 'mp4'
|
|
120
114
|
} else {
|
|
121
115
|
const ext = filename.split('.').pop()
|
|
122
116
|
if (['doc', 'xls', 'ppt', 'pdf'].includes(ext)) {
|
|
123
|
-
|
|
117
|
+
file_type = ext
|
|
124
118
|
} else {
|
|
125
|
-
|
|
119
|
+
file_type = 'stream'
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
const
|
|
123
|
+
const form: CreateImFileForm = {
|
|
124
|
+
file_type,
|
|
125
|
+
file: new File([data], filename, { type }),
|
|
126
|
+
file_name: filename,
|
|
127
|
+
}
|
|
128
|
+
if (attrs.duration) {
|
|
129
|
+
form.duration = attrs.duration
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const { file_key } = await this.bot.internal.createImFile(form)
|
|
130
133
|
await this.post({
|
|
131
134
|
msg_type: _type === 'video' ? 'media' : _type,
|
|
132
135
|
content: JSON.stringify({ file_key }),
|