Skip to content

Commit 6ee0a70

Browse files
authored
docs: add message button docs (#138)
1 parent 6be8e62 commit 6ee0a70

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
164 KB
Loading

docs/develop/nodesdk/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
{ title: '成员对象(Member)', path: 'model/member' },
2626
{ title: '频道身份组对象(Role)', path: 'model/role' },
2727
{ title: '消息对象(Message)', path: 'model/message' },
28+
{title: '消息按钮对象(InlineKeyboard)', path: 'model/inline_keyboard'},
2829
{ title: '私信对象(DMS)', path: 'model/dms' },
2930
{ title: '公告对象(Announce)', path: 'model/announce' },
3031
{ title: '精华消息对象(PinsMessage)', path: 'model/pins_message.md' },
@@ -104,6 +105,7 @@ module.exports = {
104105
'message/post_ark_messages',
105106
'message/message_format',
106107
'message/post_reference_messages',
108+
'message/post_keyboard_message.md',
107109
],
108110
},
109111
{
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# 发送带有按钮的消息
2+
3+
## 效果
4+
5+
![keyboard](../../../.vuepress/public/images/node-sdk/keyboard.png)
6+
7+
## 功能描述
8+
9+
通过在 `MessageToCreate` 中指定 `keyboard` 字段发送带按钮的消息,支持 `keyboard 模版``自定义 keyboard` 两种请求格式。
10+
11+
- 要求操作人在该子频道具有`发送消息`和 对应`消息按钮组件` 的权限。
12+
- 请求参数 `keyboard 模版``自定义 keyboard` 只能单一传值。
13+
- `keyboard 模版`
14+
- 调用前需要先申请消息按钮组件模板,这一步会得到一个模板 id,在请求时填在 `keyboard` 字段上。
15+
- 申请消息按钮组件模板需要提供响应的 json,具体格式参考 [InlineKeyboard](../model/inline_keyboard.md#InlineKeyboard)
16+
- 仅 markdown 消息支持消息按钮。
17+
18+
## 使用示例
19+
20+
### 1:使用 keyboard 模版
21+
22+
```ts
23+
async function demo() {
24+
let { data } = await client.messageApi.postMessage(channelID, {
25+
markdown: {
26+
template_id: 1,
27+
params: [
28+
{
29+
key: 'title',
30+
value: ['标题'],
31+
},
32+
],
33+
},
34+
msg_id: 'xxxxxx',
35+
keyboard: {
36+
id: '123',
37+
},
38+
});
39+
}
40+
```
41+
42+
### 2:使用自定义 keyboard
43+
44+
```ts
45+
async function demo() {
46+
let { data } = await client.messageApi.postMessage(channelID, {
47+
markdown: {
48+
template_id: 1,
49+
params: [
50+
{
51+
key: 'title',
52+
value: ['标题'],
53+
},
54+
],
55+
},
56+
msg_id: 'xxxxxx',
57+
keyboard: {
58+
content: {
59+
rows: [
60+
{
61+
buttons: [
62+
{
63+
id: '1',
64+
render_data: {
65+
label: 'AtBot-按钮1',
66+
visited_label: '点击后按钮1上文字',
67+
},
68+
action: {
69+
type: 2,
70+
permission: {
71+
type: 2,
72+
specify_role_ids: ['1', '2', '3'],
73+
},
74+
click_limit: 10,
75+
unsupport_tips: '编辑-兼容文本',
76+
data: '/搜索',
77+
at_bot_show_channel_list: true,
78+
},
79+
},
80+
],
81+
},
82+
],
83+
bot_appid: 123123123,
84+
},
85+
},
86+
});
87+
}
88+
```
89+
90+
91+
## 返回说明
92+
93+
成功返回 [Message](../model/message.md#message) 对象
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 消息按钮组件(InlineKeyboard)<Badge text="v1.0.0" />
2+
3+
### InlineKeyboard
4+
5+
| 字段名 | 类型 | 描述 |
6+
|-----------|-----------------------------------------------------|---------------------------|
7+
| rows | [InlineKeyboardRow](#inlinekeyboardrow) 消息按钮组件行对象数组 | 数组的一项代表消息按钮组件的一行,最多含有 5 行 |
8+
9+
### InlineKeyboardRow
10+
11+
| 字段名 | 类型 | 描述 |
12+
|---------|--------------------------|--------------------------------------------------|
13+
| buttons | [Button](#button) 按钮对象数组 | 数组的一项代表一个按钮,每个 InlineKeyboardRow 最多含有 5 个 Button |
14+
15+
### Button
16+
17+
| 字段名 | 类型 | 描述 |
18+
|-------------|------------------------------------|--------------|
19+
| id | string | 按钮 id |
20+
| render_data | [RenderData](#renderdata) 按纽渲染展示对象 | 用于设定按钮的显示效果 |
21+
| action | [Action](#action) 该按纽操作相关字段 | 用于设定按钮点击后的操作 |
22+
23+
### RenderData
24+
25+
| 字段名 | 类型 | 描述 |
26+
|---------------|--------|-------------------------------------|
27+
| label | string | 按纽上的文字 |
28+
| visited_label | string | 点击后按纽上文字 |
29+
| style | int | 按钮样式,参考 [RenderStyle](#renderstyle) |
30+
31+
### RenderStyle
32+
33+
| 字段名 | 类型 | 描述 |
34+
|-----|-----|------|
35+
| 0 | int | 灰色线框 |
36+
| 1 | int | 蓝色线框 |
37+
38+
### Action
39+
40+
| 字段名 | 类型 | 描述 |
41+
| ------------------------ | ------------------------------- | ---------------------------------------------- |
42+
| type | int | 操作类型,参考 [ActionType](#actiontype) |
43+
| permission | [Permission](#permission) 对象 | 用于设定操作按钮所需的权限 |
44+
| click_limit | int | 可点击的次数, 默认不限 |
45+
| data | string | 操作相关数据 |
46+
| at_bot_show_channel_list | bool | false:不弹出子频道选择器 true:弹出子频道选择器 |
47+
48+
### ActionType
49+
|| 描述 |
50+
| --- | ------------------------------------------------------------------------------------------- |
51+
| 0 | http 或 小程序 客户端识别 schem, data字段为链接 |
52+
| 1 | 回调后台接口, data 传给后台 |
53+
| 2 | at机器人, 根据 at_bot_show_channel_list 决定在当前频道或用户选择频道,自动在输入框 @bot data |
54+
55+
### Permission
56+
57+
| 字段名 | 类型 | 描述 |
58+
| ---------------- | ----------- | ------------------------------------------------ |
59+
| type | int | 权限类型,参考 [PermissionType](#permissiontype) |
60+
| specify_role_ids | string 数组 | 有权限的身份组id的列表 |
61+
| specify_user_ids | string 数组 | 有权限的用户id的列表 |
62+
63+
### PermissionType
64+
65+
|| 描述 |
66+
| --- | ---------------- |
67+
| 0 | 指定用户可操作 |
68+
| 1 | 仅管理者可操作 |
69+
| 2 | 所有人可操作 |
70+
| 3 | 指定身份组可操作 |

0 commit comments

Comments
 (0)