@milerliu/feishu 0.1.13 → 0.1.15
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/package.json +1 -1
- package/src/send.ts +43 -59
package/package.json
CHANGED
package/src/send.ts
CHANGED
|
@@ -48,10 +48,14 @@ export async function sendStreamingMessageFeishu(params: {
|
|
|
48
48
|
rawText = buildMentionedMessage(mentions, rawText);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// Create
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
// Create interactive card with streaming_update enabled
|
|
52
|
+
const card = {
|
|
53
|
+
header: {
|
|
54
|
+
title: {
|
|
55
|
+
tag: "plain_text",
|
|
56
|
+
content: "AI 回复",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
55
59
|
config: {
|
|
56
60
|
wide_screen_mode: true,
|
|
57
61
|
streaming_update: true,
|
|
@@ -64,37 +68,14 @@ export async function sendStreamingMessageFeishu(params: {
|
|
|
64
68
|
],
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
const cardContent = JSON.stringify(
|
|
68
|
-
|
|
69
|
-
// Create card instance
|
|
70
|
-
const cardResponse = await (client as any).cardkit.v1.card.create({
|
|
71
|
-
data: {
|
|
72
|
-
type: "adaptive",
|
|
73
|
-
data: cardContent,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
71
|
+
const cardContent = JSON.stringify(card);
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
console.error(`Card creation failed: ${cardResponse.msg}`);
|
|
79
|
-
// Fallback to regular card
|
|
80
|
-
const fallbackCard = buildMarkdownCard(rawText);
|
|
81
|
-
return sendCardFeishu({ cfg, to, card: fallbackCard });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const cardId = cardResponse.data?.card_id;
|
|
85
|
-
if (!cardId) {
|
|
86
|
-
console.error('No card_id returned');
|
|
87
|
-
const fallbackCard = buildMarkdownCard(rawText);
|
|
88
|
-
return sendCardFeishu({ cfg, to, card: fallbackCard });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Send the card as a message
|
|
92
|
-
const messageContent = JSON.stringify({ card_id: cardId });
|
|
73
|
+
// Create the card message
|
|
93
74
|
const messageResponse = await client.im.message.create({
|
|
94
75
|
params: { receive_id_type: receiveIdType },
|
|
95
76
|
data: {
|
|
96
77
|
receive_id: receiveId,
|
|
97
|
-
content:
|
|
78
|
+
content: cardContent,
|
|
98
79
|
msg_type: "interactive",
|
|
99
80
|
},
|
|
100
81
|
});
|
|
@@ -105,50 +86,52 @@ export async function sendStreamingMessageFeishu(params: {
|
|
|
105
86
|
|
|
106
87
|
const messageId = messageResponse.data?.message_id ?? "unknown";
|
|
107
88
|
|
|
108
|
-
// Now
|
|
109
|
-
//
|
|
110
|
-
const chunkSize =
|
|
89
|
+
// Now update the message multiple times for streaming effect
|
|
90
|
+
// Use im.v1.message.update API
|
|
91
|
+
const chunkSize = 500;
|
|
111
92
|
const chunks: string[] = [];
|
|
112
93
|
for (let i = 0; i < rawText.length; i += chunkSize) {
|
|
113
94
|
chunks.push(rawText.slice(i, i + chunkSize));
|
|
114
95
|
}
|
|
115
96
|
|
|
116
|
-
//
|
|
97
|
+
// Send updates with delay
|
|
117
98
|
for (let i = 0; i < chunks.length; i++) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
const updateCard = {
|
|
100
|
+
header: {
|
|
101
|
+
title: {
|
|
102
|
+
tag: "plain_text",
|
|
103
|
+
content: "AI 回复",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
config: {
|
|
107
|
+
wide_screen_mode: true,
|
|
108
|
+
streaming_update: true,
|
|
109
|
+
},
|
|
110
|
+
elements: [
|
|
111
|
+
{
|
|
130
112
|
tag: "markdown",
|
|
131
113
|
content: chunks[i],
|
|
132
114
|
},
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const updateContent = JSON.stringify(updateCard);
|
|
135
119
|
|
|
136
120
|
try {
|
|
137
|
-
await (client as any).
|
|
138
|
-
path: {
|
|
121
|
+
await (client as any).im.v1.message.update({
|
|
122
|
+
path: { message_id: messageId },
|
|
139
123
|
data: {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
actions,
|
|
124
|
+
msg_type: "interactive",
|
|
125
|
+
content: updateContent,
|
|
143
126
|
},
|
|
144
127
|
});
|
|
145
|
-
|
|
146
|
-
// Delay between updates for streaming effect
|
|
147
|
-
if (i < chunks.length - 1) {
|
|
148
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
149
|
-
}
|
|
150
128
|
} catch (err) {
|
|
151
|
-
console.error(`
|
|
129
|
+
console.error(`Message update failed: ${err}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Delay between updates
|
|
133
|
+
if (i < chunks.length - 1) {
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
152
135
|
}
|
|
153
136
|
}
|
|
154
137
|
|
|
@@ -396,6 +379,7 @@ export async function updateCardFeishu(params: {
|
|
|
396
379
|
*/
|
|
397
380
|
export function buildMarkdownCard(text: string): Record<string, unknown> {
|
|
398
381
|
return {
|
|
382
|
+
type: "adaptive",
|
|
399
383
|
config: {
|
|
400
384
|
wide_screen_mode: true,
|
|
401
385
|
},
|