@desplega.ai/slack-mock 0.4.0 → 0.4.1
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 +3 -1
- package/dist/cli.js +1 -1
- package/dist/{index-y82vvfa1.js → index-86bw4z6k.js} +2054 -2043
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/web-api.ts +17 -2
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/src/web-api.ts
CHANGED
|
@@ -65,10 +65,23 @@ function botFields(ctx: ApiContext): Partial<SlackMessage> {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* `markdown_text` is Slack's markdown input (`**bold**`, lists, code fences).
|
|
70
|
+
* Slack rejects it next to `text` or `blocks` and renders it server-side; the
|
|
71
|
+
* mock keeps the markdown as the message `text`.
|
|
72
|
+
*/
|
|
73
|
+
function markdownText(args: Args): string | undefined {
|
|
74
|
+
const markdown = str(args, "markdown_text");
|
|
75
|
+
if (markdown === undefined) return undefined;
|
|
76
|
+
if (str(args, "text") || (Array.isArray(args.blocks) && args.blocks.length))
|
|
77
|
+
throw new SlackApiError("markdown_text_conflict");
|
|
78
|
+
return markdown;
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
function messageContent(
|
|
69
82
|
args: Args,
|
|
70
83
|
): Pick<SlackMessage, "text" | "blocks" | "attachments" | "metadata"> {
|
|
71
|
-
const text = str(args, "text") ?? "";
|
|
84
|
+
const text = markdownText(args) ?? str(args, "text") ?? "";
|
|
72
85
|
const blocks = Array.isArray(args.blocks) ? (args.blocks as unknown[]) : undefined;
|
|
73
86
|
const attachments = Array.isArray(args.attachments) ? (args.attachments as unknown[]) : undefined;
|
|
74
87
|
if (!text && !blocks?.length && !attachments?.length) throw new SlackApiError("no_text");
|
|
@@ -191,7 +204,9 @@ export const handlers: Record<string, Handler> = {
|
|
|
191
204
|
if (existing.user !== ctx.actor.userId && !ctx.actor.isBot)
|
|
192
205
|
throw new SlackApiError("cant_update_message");
|
|
193
206
|
const patch: Partial<SlackMessage> = {};
|
|
194
|
-
|
|
207
|
+
const markdown = markdownText(args);
|
|
208
|
+
if (markdown !== undefined) patch.text = markdown;
|
|
209
|
+
else if (args.text !== undefined) patch.text = str(args, "text") ?? "";
|
|
195
210
|
if (args.blocks !== undefined)
|
|
196
211
|
patch.blocks = Array.isArray(args.blocks) ? (args.blocks as unknown[]) : undefined;
|
|
197
212
|
if (args.attachments !== undefined)
|