@channel.io/app-sdk-core 0.1.1 → 0.3.0
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/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/message.d.ts +83 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +11 -0
- package/dist/types/message.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mention.d.ts +22 -0
- package/dist/utils/mention.d.ts.map +1 -0
- package/dist/utils/mention.js +37 -0
- package/dist/utils/mention.js.map +1 -0
- package/dist/utils/message-builder.d.ts +72 -0
- package/dist/utils/message-builder.d.ts.map +1 -0
- package/dist/utils/message-builder.js +103 -0
- package/dist/utils/message-builder.js.map +1 -0
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/types/index.js
CHANGED
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message types for Channel Talk messages.
|
|
3
|
+
*
|
|
4
|
+
* These types match the proto definitions in ch-proto/coreapi/v1/model/message.proto
|
|
5
|
+
* and ch-proto/coreapi/v1/service/message.proto.
|
|
6
|
+
*
|
|
7
|
+
* Key design: blocks, buttons, and files are SEPARATE fields in WriteMessageRequestDto,
|
|
8
|
+
* not a single polymorphic array.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Text block -- renders a text message.
|
|
12
|
+
* Supports Channel Talk markup including mentions.
|
|
13
|
+
*/
|
|
14
|
+
export interface TextBlock {
|
|
15
|
+
type: "text";
|
|
16
|
+
/** Text content (may contain Channel Talk markup such as mentions) */
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Divider block -- renders a horizontal separator.
|
|
21
|
+
*/
|
|
22
|
+
export interface DividerBlock {
|
|
23
|
+
type: "divider";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A single message block. Discriminated on `type`.
|
|
27
|
+
* Only text and divider blocks belong in the `blocks` array.
|
|
28
|
+
*/
|
|
29
|
+
export type MessageBlock = TextBlock | DividerBlock;
|
|
30
|
+
/** Color variants for message buttons, matching MessageColorVariant proto enum. */
|
|
31
|
+
export type MessageButtonColorVariant = "cobalt" | "green" | "orange" | "red" | "black" | "pink" | "purple";
|
|
32
|
+
/** Triggers an app command when the button is clicked. */
|
|
33
|
+
export interface CommandAction {
|
|
34
|
+
type: "command";
|
|
35
|
+
appId: string;
|
|
36
|
+
name: string;
|
|
37
|
+
params?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/** Opens a web URL when the button is clicked. */
|
|
40
|
+
export interface WebAction {
|
|
41
|
+
type: "web";
|
|
42
|
+
url: string;
|
|
43
|
+
}
|
|
44
|
+
/** Opens a WAM (Web App Module) when the button is clicked. */
|
|
45
|
+
export interface WAMAction {
|
|
46
|
+
type: "wam";
|
|
47
|
+
appId: string;
|
|
48
|
+
name: string;
|
|
49
|
+
clientId?: string;
|
|
50
|
+
wamArgs?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/** Discriminated union of button action types. */
|
|
53
|
+
export type MessageButtonAction = CommandAction | WebAction | WAMAction;
|
|
54
|
+
/**
|
|
55
|
+
* A message button, matching Message.Button proto.
|
|
56
|
+
* title: 1-30 characters, required.
|
|
57
|
+
* action: required (oneof CommandAction | WebAction | WAMAction).
|
|
58
|
+
*/
|
|
59
|
+
export interface MessageButton {
|
|
60
|
+
title: string;
|
|
61
|
+
colorVariant?: MessageButtonColorVariant;
|
|
62
|
+
action: MessageButtonAction;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A message file attachment, matching Message.File proto.
|
|
66
|
+
* All fields are required.
|
|
67
|
+
*/
|
|
68
|
+
export interface MessageFile {
|
|
69
|
+
url: string;
|
|
70
|
+
mime: string;
|
|
71
|
+
fileName: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The payload returned by MessageBuilder.build().
|
|
75
|
+
* Matches the structure of WriteMessageRequestDto with blocks, buttons, and files
|
|
76
|
+
* as separate fields.
|
|
77
|
+
*/
|
|
78
|
+
export interface MessagePayload {
|
|
79
|
+
blocks: MessageBlock[];
|
|
80
|
+
buttons?: MessageButton[];
|
|
81
|
+
files?: MessageFile[];
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;;GAGG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AC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message types for Channel Talk messages.
|
|
3
|
+
*
|
|
4
|
+
* These types match the proto definitions in ch-proto/coreapi/v1/model/message.proto
|
|
5
|
+
* and ch-proto/coreapi/v1/service/message.proto.
|
|
6
|
+
*
|
|
7
|
+
* Key design: blocks, buttons, and files are SEPARATE fields in WriteMessageRequestDto,
|
|
8
|
+
* not a single polymorphic array.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
package/dist/utils/index.js
CHANGED
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Channel Talk manager mention markup string.
|
|
3
|
+
*
|
|
4
|
+
* Both `managerId` and `name` are HTML-escaped to prevent markup injection.
|
|
5
|
+
*
|
|
6
|
+
* @param managerId - The manager's ID
|
|
7
|
+
* @param name - Display name shown after the "@" symbol
|
|
8
|
+
* @returns Formatted mention string for use in text blocks
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* mention("123", "Alice")
|
|
13
|
+
* // => '<link type="manager" value="123">@Alice</link>'
|
|
14
|
+
*
|
|
15
|
+
* // Use inside MessageBuilder:
|
|
16
|
+
* new MessageBuilder()
|
|
17
|
+
* .text(`Hello ${mention("123", "Alice")}!`)
|
|
18
|
+
* .build();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function mention(managerId: string, name: string): string;
|
|
22
|
+
//# sourceMappingURL=mention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.d.ts","sourceRoot":"","sources":["../../src/utils/mention.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes HTML special characters to prevent markup injection.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
function escapeHtml(str) {
|
|
7
|
+
return str
|
|
8
|
+
.replace(/&/g, "&")
|
|
9
|
+
.replace(/</g, "<")
|
|
10
|
+
.replace(/>/g, ">")
|
|
11
|
+
.replace(/"/g, """)
|
|
12
|
+
.replace(/'/g, "'");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Channel Talk manager mention markup string.
|
|
16
|
+
*
|
|
17
|
+
* Both `managerId` and `name` are HTML-escaped to prevent markup injection.
|
|
18
|
+
*
|
|
19
|
+
* @param managerId - The manager's ID
|
|
20
|
+
* @param name - Display name shown after the "@" symbol
|
|
21
|
+
* @returns Formatted mention string for use in text blocks
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* mention("123", "Alice")
|
|
26
|
+
* // => '<link type="manager" value="123">@Alice</link>'
|
|
27
|
+
*
|
|
28
|
+
* // Use inside MessageBuilder:
|
|
29
|
+
* new MessageBuilder()
|
|
30
|
+
* .text(`Hello ${mention("123", "Alice")}!`)
|
|
31
|
+
* .build();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function mention(managerId, name) {
|
|
35
|
+
return `<link type="manager" value="${escapeHtml(managerId)}">@${escapeHtml(name)}</link>`;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=mention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.js","sourceRoot":"","sources":["../../src/utils/mention.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG;SACP,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,IAAY;IACrD,OAAO,+BAA+B,UAAU,CAAC,SAAS,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { MessageButtonAction, MessageButtonColorVariant, MessagePayload } from "../types/message.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for composing Channel Talk messages.
|
|
4
|
+
*
|
|
5
|
+
* Blocks (text, divider) go into the `blocks` array.
|
|
6
|
+
* Buttons go into a separate `buttons` array (max 2).
|
|
7
|
+
* Files go into a separate `files` array (max 30).
|
|
8
|
+
*
|
|
9
|
+
* This matches the proto structure of WriteMessageRequestDto.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { MessageBuilder, mention } from '@channel.io/app-sdk-core';
|
|
14
|
+
*
|
|
15
|
+
* const payload = new MessageBuilder()
|
|
16
|
+
* .text(`Hello ${mention("mgr-1", "Alice")}!`)
|
|
17
|
+
* .divider()
|
|
18
|
+
* .text("Check this out:")
|
|
19
|
+
* .button("Open Dashboard", { type: "web", url: "https://example.com" })
|
|
20
|
+
* .file("https://example.com/report.pdf", "application/pdf", "report.pdf")
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // payload.blocks -> [TextBlock, DividerBlock, TextBlock]
|
|
24
|
+
* // payload.buttons -> [{ title: "Open Dashboard", action: { ... } }]
|
|
25
|
+
* // payload.files -> [{ url: "...", mime: "...", fileName: "..." }]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class MessageBuilder {
|
|
29
|
+
private readonly _blocks;
|
|
30
|
+
private readonly _buttons;
|
|
31
|
+
private readonly _files;
|
|
32
|
+
/**
|
|
33
|
+
* Append a text block.
|
|
34
|
+
*
|
|
35
|
+
* @param value - Text content (may include mention markup)
|
|
36
|
+
*/
|
|
37
|
+
text(value: string): this;
|
|
38
|
+
/**
|
|
39
|
+
* Append a horizontal divider block.
|
|
40
|
+
*/
|
|
41
|
+
divider(): this;
|
|
42
|
+
/**
|
|
43
|
+
* Add a button to the message.
|
|
44
|
+
* Buttons are a separate field from blocks (max 2 per message).
|
|
45
|
+
*
|
|
46
|
+
* @param title - Button display label (1-30 characters)
|
|
47
|
+
* @param action - The action to perform when clicked
|
|
48
|
+
* @param colorVariant - Optional color variant
|
|
49
|
+
*/
|
|
50
|
+
button(title: string, action: MessageButtonAction, colorVariant?: MessageButtonColorVariant): this;
|
|
51
|
+
/**
|
|
52
|
+
* Add a file attachment to the message.
|
|
53
|
+
* Files are a separate field from blocks (max 30 per message).
|
|
54
|
+
*
|
|
55
|
+
* @param url - File URL
|
|
56
|
+
* @param mime - MIME type (e.g. "image/png", "application/pdf")
|
|
57
|
+
* @param fileName - Display file name
|
|
58
|
+
*/
|
|
59
|
+
file(url: string, mime: string, fileName: string): this;
|
|
60
|
+
/**
|
|
61
|
+
* Remove all accumulated blocks, buttons, and files, allowing the builder to be reused.
|
|
62
|
+
*/
|
|
63
|
+
reset(): this;
|
|
64
|
+
/**
|
|
65
|
+
* Return the accumulated message payload.
|
|
66
|
+
* The builder can continue to be used after calling build().
|
|
67
|
+
*
|
|
68
|
+
* @returns A MessagePayload with blocks, and optionally buttons and files.
|
|
69
|
+
*/
|
|
70
|
+
build(): MessagePayload;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=message-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-builder.d.ts","sourceRoot":"","sources":["../../src/utils/message-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,mBAAmB,EACnB,yBAAyB,EAEzB,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKzB;;OAEG;IACH,OAAO,IAAI,IAAI;IAKf;;;;;;;OAOG;IACH,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,IAAI;IASP;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKvD;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;;;;OAKG;IACH,KAAK,IAAI,cAAc;CAYxB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent builder for composing Channel Talk messages.
|
|
3
|
+
*
|
|
4
|
+
* Blocks (text, divider) go into the `blocks` array.
|
|
5
|
+
* Buttons go into a separate `buttons` array (max 2).
|
|
6
|
+
* Files go into a separate `files` array (max 30).
|
|
7
|
+
*
|
|
8
|
+
* This matches the proto structure of WriteMessageRequestDto.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { MessageBuilder, mention } from '@channel.io/app-sdk-core';
|
|
13
|
+
*
|
|
14
|
+
* const payload = new MessageBuilder()
|
|
15
|
+
* .text(`Hello ${mention("mgr-1", "Alice")}!`)
|
|
16
|
+
* .divider()
|
|
17
|
+
* .text("Check this out:")
|
|
18
|
+
* .button("Open Dashboard", { type: "web", url: "https://example.com" })
|
|
19
|
+
* .file("https://example.com/report.pdf", "application/pdf", "report.pdf")
|
|
20
|
+
* .build();
|
|
21
|
+
*
|
|
22
|
+
* // payload.blocks -> [TextBlock, DividerBlock, TextBlock]
|
|
23
|
+
* // payload.buttons -> [{ title: "Open Dashboard", action: { ... } }]
|
|
24
|
+
* // payload.files -> [{ url: "...", mime: "...", fileName: "..." }]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class MessageBuilder {
|
|
28
|
+
_blocks = [];
|
|
29
|
+
_buttons = [];
|
|
30
|
+
_files = [];
|
|
31
|
+
/**
|
|
32
|
+
* Append a text block.
|
|
33
|
+
*
|
|
34
|
+
* @param value - Text content (may include mention markup)
|
|
35
|
+
*/
|
|
36
|
+
text(value) {
|
|
37
|
+
this._blocks.push({ type: "text", value });
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Append a horizontal divider block.
|
|
42
|
+
*/
|
|
43
|
+
divider() {
|
|
44
|
+
this._blocks.push({ type: "divider" });
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Add a button to the message.
|
|
49
|
+
* Buttons are a separate field from blocks (max 2 per message).
|
|
50
|
+
*
|
|
51
|
+
* @param title - Button display label (1-30 characters)
|
|
52
|
+
* @param action - The action to perform when clicked
|
|
53
|
+
* @param colorVariant - Optional color variant
|
|
54
|
+
*/
|
|
55
|
+
button(title, action, colorVariant) {
|
|
56
|
+
const btn = { title, action };
|
|
57
|
+
if (colorVariant !== undefined) {
|
|
58
|
+
btn.colorVariant = colorVariant;
|
|
59
|
+
}
|
|
60
|
+
this._buttons.push(btn);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Add a file attachment to the message.
|
|
65
|
+
* Files are a separate field from blocks (max 30 per message).
|
|
66
|
+
*
|
|
67
|
+
* @param url - File URL
|
|
68
|
+
* @param mime - MIME type (e.g. "image/png", "application/pdf")
|
|
69
|
+
* @param fileName - Display file name
|
|
70
|
+
*/
|
|
71
|
+
file(url, mime, fileName) {
|
|
72
|
+
this._files.push({ url, mime, fileName });
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Remove all accumulated blocks, buttons, and files, allowing the builder to be reused.
|
|
77
|
+
*/
|
|
78
|
+
reset() {
|
|
79
|
+
this._blocks.length = 0;
|
|
80
|
+
this._buttons.length = 0;
|
|
81
|
+
this._files.length = 0;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Return the accumulated message payload.
|
|
86
|
+
* The builder can continue to be used after calling build().
|
|
87
|
+
*
|
|
88
|
+
* @returns A MessagePayload with blocks, and optionally buttons and files.
|
|
89
|
+
*/
|
|
90
|
+
build() {
|
|
91
|
+
const payload = {
|
|
92
|
+
blocks: [...this._blocks],
|
|
93
|
+
};
|
|
94
|
+
if (this._buttons.length > 0) {
|
|
95
|
+
payload.buttons = [...this._buttons];
|
|
96
|
+
}
|
|
97
|
+
if (this._files.length > 0) {
|
|
98
|
+
payload.files = [...this._files];
|
|
99
|
+
}
|
|
100
|
+
return payload;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=message-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-builder.js","sourceRoot":"","sources":["../../src/utils/message-builder.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,GAAmB,EAAE,CAAC;IAC7B,QAAQ,GAAoB,EAAE,CAAC;IAC/B,MAAM,GAAkB,EAAE,CAAC;IAE5C;;;;OAIG;IACH,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CACJ,KAAa,EACb,MAA2B,EAC3B,YAAwC;QAExC,MAAM,GAAG,GAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAC7C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,GAAG,CAAC,YAAY,GA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