@larksuiteoapi/node-sdk 1.14.0 → 1.16.0
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/README.md +68 -0
- package/README.zh.md +69 -0
- package/es/index.js +672 -92
- package/lib/index.js +672 -91
- package/package.json +1 -1
- package/types/index.d.ts +1042 -83
package/README.md
CHANGED
|
@@ -185,6 +185,74 @@ const res = await client. request({
|
|
|
185
185
|
params: {},
|
|
186
186
|
});
|
|
187
187
|
````
|
|
188
|
+
#### Message Card
|
|
189
|
+
When sending [message card](https://open.feishu.cn/document/ukTMukTMukTM/uczM3QjL3MzN04yNzcDN), it will first be in the [message card builder](https://open.feishu.cn/document/ukTMukTMukTM/uYzM3QjL2MzN04iNzcDN/message-card-builder) to build a message card template, get the generated template json, replace the content-related parts with data, and use the result as a parameter to support the message card api. Such as sending a simple message card with `title` and `content`:
|
|
190
|
+
```typescript
|
|
191
|
+
client.im.message.create({
|
|
192
|
+
params: {
|
|
193
|
+
receive_id_type: 'chat_id',
|
|
194
|
+
},
|
|
195
|
+
data: {
|
|
196
|
+
receive_id: 'your receive_id',
|
|
197
|
+
content: JSON.stringify({
|
|
198
|
+
"config": {
|
|
199
|
+
"wide_screen_mode": true
|
|
200
|
+
},
|
|
201
|
+
"elements": [
|
|
202
|
+
{
|
|
203
|
+
"tag": "markdown",
|
|
204
|
+
"content": "Card Content"
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
"header": {
|
|
208
|
+
"template": "blue",
|
|
209
|
+
"title": {
|
|
210
|
+
"content": "Card Title",
|
|
211
|
+
"tag": "plain_text"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
),
|
|
216
|
+
msg_type: 'interactive'
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
```
|
|
220
|
+

|
|
221
|
+
There will be a problem: **If the content of the message card is relatively rich, the generated template json is relatively large, and there will be more content that needs to be filled with data, and manual maintenance is more cumbersome**. To solve this problem, The Open-Platform provides the ability of [Template Message](https://open.feishu.cn/document/tools-and-resources/message-card-builder#3e1f2c7c).When sending a message card, you only need to provide the template id and the data content of the template. The sdk encapsulates this ability in terms of calling, and the interface that supports message cards will synchronously add a ByCard calling method, only need to pass `template_id` and `template_variable`. The above call can be rewritten as:
|
|
222
|
+
```typescript
|
|
223
|
+
client.im.message.createByCard({
|
|
224
|
+
params: {
|
|
225
|
+
receive_id_type: 'chat_id',
|
|
226
|
+
},
|
|
227
|
+
data: {
|
|
228
|
+
receive_id: 'your receive_id',
|
|
229
|
+
template_id: 'your template_id',
|
|
230
|
+
template_variable: {
|
|
231
|
+
content: "Card Content",
|
|
232
|
+
title: "Card Title"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
If you want to quickly experience Message Card, you can use a basic card built into the sdk:
|
|
238
|
+
```typescript
|
|
239
|
+
import * as lark from '@larksuiteoapi/node-sdk';
|
|
240
|
+
|
|
241
|
+
client.im.message.create({
|
|
242
|
+
params: {
|
|
243
|
+
receive_id_type: 'chat_id',
|
|
244
|
+
},
|
|
245
|
+
data: {
|
|
246
|
+
receive_id: 'your receive_id',
|
|
247
|
+
content: lark.messageCard.defaultCard({
|
|
248
|
+
title: 'Card Title',
|
|
249
|
+
content: 'Card Content'
|
|
250
|
+
}),
|
|
251
|
+
msg_type: 'interactive'
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
```
|
|
255
|
+

|
|
188
256
|
|
|
189
257
|
#### Configure request options
|
|
190
258
|
If you want to modify the parameters of the request during the API call, such as carrying some headers, custom tenantToken, etc., you can use the second parameter of the request method to modify:
|
package/README.zh.md
CHANGED
|
@@ -184,6 +184,75 @@ const res = await client.request({
|
|
|
184
184
|
params: {},
|
|
185
185
|
});
|
|
186
186
|
```
|
|
187
|
+
#### 消息卡片
|
|
188
|
+
在发送[消息卡片](https://open.feishu.cn/document/ukTMukTMukTM/uczM3QjL3MzN04yNzcDN)信息时,会先在[消息卡片搭建工具](https://open.feishu.cn/document/ukTMukTMukTM/uYzM3QjL2MzN04iNzcDN/message-card-builder)中搭建出消息卡片的模版,拿到生成的模版json,用数据替换其中内容相关的部分,将结果作为支持消息卡片api的参数来使用。如发送一个简单的具有`title`和`content`的消息卡片:
|
|
189
|
+
```typescript
|
|
190
|
+
client.im.message.create({
|
|
191
|
+
params: {
|
|
192
|
+
receive_id_type: 'chat_id',
|
|
193
|
+
},
|
|
194
|
+
data: {
|
|
195
|
+
receive_id: 'your receive_id',
|
|
196
|
+
content: JSON.stringify({
|
|
197
|
+
"config": {
|
|
198
|
+
"wide_screen_mode": true
|
|
199
|
+
},
|
|
200
|
+
"elements": [
|
|
201
|
+
{
|
|
202
|
+
"tag": "markdown",
|
|
203
|
+
"content": "Card Content"
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"header": {
|
|
207
|
+
"template": "blue",
|
|
208
|
+
"title": {
|
|
209
|
+
"content": "Card Title",
|
|
210
|
+
"tag": "plain_text"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
),
|
|
215
|
+
msg_type: 'interactive'
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
```
|
|
219
|
+

|
|
220
|
+
这样使用会有一个问题:**如果消息卡片内容比较丰富,生成的模版json比较大,与之相关需要数据填充的内容部分也会比较多,手动维护比较繁琐**。针对这个问题,开放平台提供了[模版消息](https://open.feishu.cn/document/tools-and-resources/message-card-builder#3e1f2c7c)的能力,发送消息卡片时只需要提供模版id和模版的数据内容即可。sdk对这个能力进行了调用上的封装,支持消息卡片的接口会同步的增加一个ByCard的调用方式,只需要传递`template_id`和`template_variable`即可。如上面的调用可以改写成:
|
|
221
|
+
```typescript
|
|
222
|
+
client.im.message.createByCard({
|
|
223
|
+
params: {
|
|
224
|
+
receive_id_type: 'chat_id',
|
|
225
|
+
},
|
|
226
|
+
data: {
|
|
227
|
+
receive_id: 'your receive_id',
|
|
228
|
+
template_id: 'your template_id',
|
|
229
|
+
template_variable: {
|
|
230
|
+
content: "Card Content",
|
|
231
|
+
title: "Card Title"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
如果想要快速体验消息卡片,可以使用sdk中内置的一个基础卡片:
|
|
237
|
+
```typescript
|
|
238
|
+
import * as lark from '@larksuiteoapi/node-sdk';
|
|
239
|
+
|
|
240
|
+
client.im.message.create({
|
|
241
|
+
params: {
|
|
242
|
+
receive_id_type: 'chat_id',
|
|
243
|
+
},
|
|
244
|
+
data: {
|
|
245
|
+
receive_id: 'your receive_id',
|
|
246
|
+
content: lark.messageCard.defaultCard({
|
|
247
|
+
title: 'Card Title',
|
|
248
|
+
content: 'Card Content'
|
|
249
|
+
}),
|
|
250
|
+
msg_type: 'interactive'
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
```
|
|
254
|
+
效果同上:
|
|
255
|
+

|
|
187
256
|
|
|
188
257
|
#### 配置请求选项
|
|
189
258
|
如果想在api调用过程中修改请求的参数,如携带一些header,自定义tenantToken等,则可以使用请求方法的第二个参数来进行修改:
|