@alemonjs/bubble 2.1.0-alpha.4 → 2.1.0-alpha.6

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.
Files changed (2) hide show
  1. package/lib/send.js +24 -8
  2. package/package.json +2 -2
package/lib/send.js CHANGED
@@ -14,7 +14,7 @@ const sendToRoom = async (client, param, val) => {
14
14
  const threadId = String(param?.thread_id ?? '');
15
15
  const messageId = param?.message_id ? String(param?.message_id) : undefined;
16
16
  const images = val.filter(item => item.type === 'Image' || item.type === 'ImageURL' || item.type === 'ImageFile');
17
- const mds = val.filter(item => item.type === 'Markdown');
17
+ const mdAndButtons = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group');
18
18
  const content = val
19
19
  .filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
20
20
  .map(item => {
@@ -72,12 +72,12 @@ const sendToRoom = async (client, param, val) => {
72
72
  const uploadRes = await client.uploadFile(bufferData, undefined, { channelId, threadId, messageId: messageId });
73
73
  const fileAttachment = uploadRes?.data?.file;
74
74
  if (!fileAttachment) {
75
- throw new Error('文件上传失败:未返回文件信息');
75
+ return [createResult(ResultCode.Ok, '文件上传失败:未返回文件信息', uploadRes)];
76
76
  }
77
77
  if (channelId) {
78
78
  const res = await client.sendMessage(channelId, {
79
79
  content: content,
80
- type: 'text',
80
+ type: 'image',
81
81
  attachments: [fileAttachment]
82
82
  });
83
83
  return [createResult(ResultCode.Ok, '完成', res)];
@@ -85,7 +85,7 @@ const sendToRoom = async (client, param, val) => {
85
85
  if (threadId) {
86
86
  const res = await client.sendDm(threadId, {
87
87
  content: content,
88
- type: 'text',
88
+ type: 'image',
89
89
  attachments: [fileAttachment]
90
90
  });
91
91
  return [createResult(ResultCode.Ok, '完成', res)];
@@ -93,8 +93,8 @@ const sendToRoom = async (client, param, val) => {
93
93
  return [createResult(ResultCode.Ok, '完成', null)];
94
94
  }
95
95
  let contentMd = '';
96
- if (mds && mds.length > 0) {
97
- mds.forEach(item => {
96
+ if (mdAndButtons && mdAndButtons.length > 0) {
97
+ mdAndButtons.forEach(item => {
98
98
  if (item.type === 'Markdown') {
99
99
  const md = item.value;
100
100
  md.forEach(line => {
@@ -141,15 +141,31 @@ const sendToRoom = async (client, param, val) => {
141
141
  }
142
142
  });
143
143
  }
144
+ else if (item.type === 'BT.group' && item.value.length > 0) {
145
+ contentMd += `<box>${item.value?.map(row => {
146
+ const val = row.value;
147
+ if (val.length === 0) {
148
+ return '';
149
+ }
150
+ return `<flex>${val.map(button => {
151
+ const value = button.value;
152
+ const options = button.options;
153
+ const autoEnter = options?.autoEnter ?? false;
154
+ const label = typeof value === 'object' ? value.title : value;
155
+ const command = options?.data || label;
156
+ return `<btn command="${command}" enter="${String(autoEnter)}" >${label}</btn>`;
157
+ }).join('')}</flex>`;
158
+ }).join('')}</box>`;
159
+ }
144
160
  });
145
161
  }
146
162
  if ((content && content.length > 0) || (contentMd && contentMd.length > 0)) {
147
163
  if (channelId) {
148
- const res = await client.sendMessage(channelId, { content: content ?? contentMd, type: 'text' });
164
+ const res = await client.sendMessage(channelId, { content: content !== '' ? content : contentMd, type: 'text' });
149
165
  return [createResult(ResultCode.Ok, '完成', res)];
150
166
  }
151
167
  if (threadId) {
152
- const res = await client.sendDm(threadId, { content: content ?? contentMd, type: 'text' });
168
+ const res = await client.sendDm(threadId, { content: content !== '' ? content : contentMd, type: 'text' });
153
169
  return [createResult(ResultCode.Ok, '完成', res)];
154
170
  }
155
171
  return [createResult(ResultCode.Ok, '完成', null)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/bubble",
3
- "version": "2.1.0-alpha.4",
3
+ "version": "2.1.0-alpha.6",
4
4
  "description": "bubble platform",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -65,4 +65,4 @@
65
65
  "type": "git",
66
66
  "url": "https://github.com/lemonade-lab/alemonjs.git"
67
67
  }
68
- }
68
+ }