@desplega.ai/slack-mock 0.1.1 → 0.1.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/dist/cli.js +1 -1
- package/dist/{index-eyfkn32t.js → index-hqq20tz9.js} +15 -5
- package/dist/index.js +1 -1
- package/dist/store.d.ts +3 -1
- package/package.json +1 -1
- package/src/render/index.ts +28 -1
- package/src/store.ts +6 -1
- package/src/web-api.ts +5 -1
package/dist/cli.js
CHANGED
|
@@ -359,10 +359,10 @@ class Store {
|
|
|
359
359
|
this.emit({ kind: "message.add", message });
|
|
360
360
|
return message;
|
|
361
361
|
}
|
|
362
|
-
updateMessage(channelId, ts, patch, editor) {
|
|
362
|
+
updateMessage(channelId, ts, patch, editor, opts = {}) {
|
|
363
363
|
const message = this.message(channelId, ts);
|
|
364
364
|
const previous = structuredClone(message);
|
|
365
|
-
Object.assign(message, patch, { edited: { user: editor, ts: nextTs() } });
|
|
365
|
+
Object.assign(message, patch, opts.markEdited === false ? {} : { edited: { user: editor, ts: nextTs() } });
|
|
366
366
|
this.emit({ kind: "message.update", message, previous });
|
|
367
367
|
return message;
|
|
368
368
|
}
|
|
@@ -1812,7 +1812,12 @@ function renderMessage(store, ctx, m, opts, flags = {}) {
|
|
|
1812
1812
|
const isApp = Boolean(m.bot_id);
|
|
1813
1813
|
const blocks = Array.isArray(m.blocks) && m.blocks.length ? m.blocks : undefined;
|
|
1814
1814
|
const body = [];
|
|
1815
|
-
if (
|
|
1815
|
+
if (m.streaming_state !== undefined) {
|
|
1816
|
+
if (m.text)
|
|
1817
|
+
body.push(`<div class="sm-text">${mrkdwnToHtml(markdownToMrkdwn(m.text), ctx)}</div>`);
|
|
1818
|
+
if (blocks)
|
|
1819
|
+
body.push(renderBlocks(blocks, ctx));
|
|
1820
|
+
} else if (blocks)
|
|
1816
1821
|
body.push(renderBlocks(blocks, ctx));
|
|
1817
1822
|
else if (m.text)
|
|
1818
1823
|
body.push(`<div class="sm-text">${mrkdwnToHtml(m.text, ctx)}</div>`);
|
|
@@ -1833,6 +1838,9 @@ function renderMessage(store, ctx, m, opts, flags = {}) {
|
|
|
1833
1838
|
const open = flags.openTs && flags.openTs === m.ts ? " sm-msg-open" : "";
|
|
1834
1839
|
return `<div class="sm-msg${flags.ephemeral ? " sm-msg-eph" : ""}${open}" data-ts="${escapeHtml(m.ts)}">${avatarHtml(m, name)}<div class="sm-msg-body"><div class="sm-msg-head"><span class="sm-name">${escapeHtml(name)}</span>${isApp ? `<span class="sm-badge">APP</span>` : ""}<span class="sm-time">${timeOf(m.ts)}</span>${streaming}</div>${body.join("")}</div></div>`;
|
|
1835
1840
|
}
|
|
1841
|
+
function markdownToMrkdwn(text) {
|
|
1842
|
+
return text.split(/(```[\s\S]*?```)/).map((part, i) => i % 2 === 1 ? part : part.replace(/\*\*(.+?)\*\*/g, "*$1*").replace(/__(.+?)__/g, "*$1*").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "<$2|$1>").replace(/^#{1,6}\s+(.+)$/gm, "*$1*").replace(/^(\s*)[-*]\s+/gm, "$1\u2022 ")).join("");
|
|
1843
|
+
}
|
|
1836
1844
|
function renderMessageList(store, ctx, messages, opts, flags = {}) {
|
|
1837
1845
|
const out = [];
|
|
1838
1846
|
let day = "";
|
|
@@ -2486,7 +2494,7 @@ var handlers = {
|
|
|
2486
2494
|
const existing = ctx.store.message(channel.id, ts);
|
|
2487
2495
|
if (existing.streaming_state !== "in_progress")
|
|
2488
2496
|
throw new SlackApiError("message_not_in_streaming_state");
|
|
2489
|
-
const message = ctx.store.updateMessage(channel.id, ts, { text: existing.text + streamText(args) }, ctx.actor.userId);
|
|
2497
|
+
const message = ctx.store.updateMessage(channel.id, ts, { text: existing.text + streamText(args) }, ctx.actor.userId, { markEdited: false });
|
|
2490
2498
|
return { channel: channel.id, ts: message.ts };
|
|
2491
2499
|
},
|
|
2492
2500
|
"chat.stopStream": (ctx, args) => {
|
|
@@ -2501,7 +2509,9 @@ var handlers = {
|
|
|
2501
2509
|
};
|
|
2502
2510
|
if (Array.isArray(args.blocks))
|
|
2503
2511
|
patch.blocks = args.blocks;
|
|
2504
|
-
const message = ctx.store.updateMessage(channel.id, ts, patch, ctx.actor.userId
|
|
2512
|
+
const message = ctx.store.updateMessage(channel.id, ts, patch, ctx.actor.userId, {
|
|
2513
|
+
markEdited: false
|
|
2514
|
+
});
|
|
2505
2515
|
return { channel: channel.id, ts, message: wireMessage(message) };
|
|
2506
2516
|
},
|
|
2507
2517
|
"chat.getPermalink": (ctx, args) => {
|
package/dist/index.js
CHANGED
package/dist/store.d.ts
CHANGED
|
@@ -115,7 +115,9 @@ export declare class Store {
|
|
|
115
115
|
addMessage(input: Omit<SlackMessage, "type" | "team" | "ts"> & {
|
|
116
116
|
ts?: string;
|
|
117
117
|
}): SlackMessage;
|
|
118
|
-
updateMessage(channelId: string, ts: string, patch: Partial<SlackMessage>, editor: string
|
|
118
|
+
updateMessage(channelId: string, ts: string, patch: Partial<SlackMessage>, editor: string, opts?: {
|
|
119
|
+
markEdited?: boolean;
|
|
120
|
+
}): SlackMessage;
|
|
119
121
|
deleteMessage(channelId: string, ts: string): SlackMessage;
|
|
120
122
|
addReaction(channelId: string, ts: string, name: string, userId: string): SlackMessage;
|
|
121
123
|
removeReaction(channelId: string, ts: string, name: string, userId: string): SlackMessage;
|
package/package.json
CHANGED
package/src/render/index.ts
CHANGED
|
@@ -455,7 +455,13 @@ function renderMessage(
|
|
|
455
455
|
const isApp = Boolean(m.bot_id);
|
|
456
456
|
const blocks = Array.isArray(m.blocks) && m.blocks.length ? m.blocks : undefined;
|
|
457
457
|
const body: string[] = [];
|
|
458
|
-
if (
|
|
458
|
+
if (m.streaming_state !== undefined) {
|
|
459
|
+
// A streamed message (chat.startStream) keeps its Markdown body; the blocks handed to
|
|
460
|
+
// chat.stopStream are appended below it, like Slack does.
|
|
461
|
+
if (m.text)
|
|
462
|
+
body.push(`<div class="sm-text">${mrkdwnToHtml(markdownToMrkdwn(m.text), ctx)}</div>`);
|
|
463
|
+
if (blocks) body.push(renderBlocks(blocks, ctx));
|
|
464
|
+
} else if (blocks) body.push(renderBlocks(blocks, ctx));
|
|
459
465
|
else if (m.text) body.push(`<div class="sm-text">${mrkdwnToHtml(m.text, ctx)}</div>`);
|
|
460
466
|
if (m.edited) body.push(`<div class="sm-edited">(edited)</div>`);
|
|
461
467
|
if (m.attachments?.length) body.push(renderAttachments(m.attachments, ctx));
|
|
@@ -479,6 +485,27 @@ function renderMessage(
|
|
|
479
485
|
return `<div class="sm-msg${flags.ephemeral ? " sm-msg-eph" : ""}${open}" data-ts="${escapeHtml(m.ts)}">${avatarHtml(m, name)}<div class="sm-msg-body"><div class="sm-msg-head"><span class="sm-name">${escapeHtml(name)}</span>${isApp ? `<span class="sm-badge">APP</span>` : ""}<span class="sm-time">${timeOf(m.ts)}</span>${streaming}</div>${body.join("")}</div></div>`;
|
|
480
486
|
}
|
|
481
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Streamed messages carry Markdown (`markdown_text`), not mrkdwn. Convert the common
|
|
490
|
+
* constructs so the mrkdwn renderer shows them: **bold**, [label](url), headings and list
|
|
491
|
+
* bullets. Fenced code blocks pass through untouched.
|
|
492
|
+
*/
|
|
493
|
+
function markdownToMrkdwn(text: string): string {
|
|
494
|
+
return text
|
|
495
|
+
.split(/(```[\s\S]*?```)/)
|
|
496
|
+
.map((part, i) =>
|
|
497
|
+
i % 2 === 1
|
|
498
|
+
? part
|
|
499
|
+
: part
|
|
500
|
+
.replace(/\*\*(.+?)\*\*/g, "*$1*")
|
|
501
|
+
.replace(/__(.+?)__/g, "*$1*")
|
|
502
|
+
.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "<$2|$1>")
|
|
503
|
+
.replace(/^#{1,6}\s+(.+)$/gm, "*$1*")
|
|
504
|
+
.replace(/^(\s*)[-*]\s+/gm, "$1• "),
|
|
505
|
+
)
|
|
506
|
+
.join("");
|
|
507
|
+
}
|
|
508
|
+
|
|
482
509
|
function renderMessageList(
|
|
483
510
|
store: Store,
|
|
484
511
|
ctx: RenderContext,
|
package/src/store.ts
CHANGED
|
@@ -421,10 +421,15 @@ export class Store {
|
|
|
421
421
|
ts: string,
|
|
422
422
|
patch: Partial<SlackMessage>,
|
|
423
423
|
editor: string,
|
|
424
|
+
opts: { markEdited?: boolean } = {},
|
|
424
425
|
): SlackMessage {
|
|
425
426
|
const message = this.message(channelId, ts);
|
|
426
427
|
const previous = structuredClone(message);
|
|
427
|
-
Object.assign(
|
|
428
|
+
Object.assign(
|
|
429
|
+
message,
|
|
430
|
+
patch,
|
|
431
|
+
opts.markEdited === false ? {} : { edited: { user: editor, ts: nextTs() } },
|
|
432
|
+
);
|
|
428
433
|
this.emit({ kind: "message.update", message, previous });
|
|
429
434
|
return message;
|
|
430
435
|
}
|
package/src/web-api.ts
CHANGED
|
@@ -242,11 +242,13 @@ export const handlers: Record<string, Handler> = {
|
|
|
242
242
|
const existing = ctx.store.message(channel.id, ts);
|
|
243
243
|
if (existing.streaming_state !== "in_progress")
|
|
244
244
|
throw new SlackApiError("message_not_in_streaming_state");
|
|
245
|
+
// Streaming appends are not edits: Slack shows no "(edited)" marker for them.
|
|
245
246
|
const message = ctx.store.updateMessage(
|
|
246
247
|
channel.id,
|
|
247
248
|
ts,
|
|
248
249
|
{ text: existing.text + streamText(args) },
|
|
249
250
|
ctx.actor.userId,
|
|
251
|
+
{ markEdited: false },
|
|
250
252
|
);
|
|
251
253
|
return { channel: channel.id, ts: message.ts };
|
|
252
254
|
},
|
|
@@ -262,7 +264,9 @@ export const handlers: Record<string, Handler> = {
|
|
|
262
264
|
text: existing.text + streamText(args),
|
|
263
265
|
};
|
|
264
266
|
if (Array.isArray(args.blocks)) patch.blocks = args.blocks as unknown[];
|
|
265
|
-
const message = ctx.store.updateMessage(channel.id, ts, patch, ctx.actor.userId
|
|
267
|
+
const message = ctx.store.updateMessage(channel.id, ts, patch, ctx.actor.userId, {
|
|
268
|
+
markEdited: false,
|
|
269
|
+
});
|
|
266
270
|
return { channel: channel.id, ts, message: wireMessage(message) };
|
|
267
271
|
},
|
|
268
272
|
|