Skip to content

Commit 68542f2

Browse files
author
Evan Greer
committed
feat: adds IterableEmbeddedMessageElements and associated classes
1 parent c350008 commit 68542f2

4 files changed

Lines changed: 166 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
export class IterableEmbeddedMessageDefaultAction {
2+
/**
3+
* The type of iterable action
4+
* For custom actions, the type is `action://` prefix followed by a custom action name
5+
*/
6+
readonly type: string;
7+
8+
/**
9+
* The url for the action when the type is `openUrl`
10+
* For custom actions, data is empty
11+
*/
12+
readonly data?: string;
13+
14+
/**
15+
* Creates an instance of `IterableEmbeddedMessageDefaultAction`.
16+
*
17+
* @param type - The type of iterable action
18+
* @param data - The url for the action when the type is `openUrl`
19+
*/
20+
constructor(type: string, data?: string) {
21+
this.type = type;
22+
this.data = data;
23+
}
24+
25+
/**
26+
* Creates an instance of `IterableEmbeddedMessageDefaultAction` from a dictionary object.
27+
*
28+
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageDefaultAction` instance.
29+
* @returns A new instance of `IterableEmbeddedMessageDefaultAction` initialized with the provided dictionary properties.
30+
*/
31+
static fromDict(
32+
dict: Partial<EmbeddedMessageDefaultActionDict>
33+
): IterableEmbeddedMessageDefaultAction {
34+
if (!dict.type) {
35+
throw new Error('type is required');
36+
}
37+
return new IterableEmbeddedMessageDefaultAction(dict.type, dict.data);
38+
}
39+
}
40+
41+
/**
42+
* An interface defining the dictionary object containing the properties for the embedded message default action.
43+
*/
44+
export interface EmbeddedMessageDefaultActionDict {
45+
type: string;
46+
data?: string;
47+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { IterableEmbeddedMessageDefaultAction } from './IterableEmbeddedMessageDefaultAction';
2+
import { IterableEmbeddedMessageElementsButton } from './IterableEmbeddedMessageElementsButton';
3+
import { IterableEmbeddedMessageText } from './IterableEmbeddedMessageText';
4+
5+
export class IterableEmbeddedMessageElements {
6+
readonly title?: string;
7+
readonly body?: string;
8+
readonly mediaUrl?: string;
9+
readonly mediaUrlCaption?: string;
10+
readonly defaultAction?: IterableEmbeddedMessageDefaultAction;
11+
readonly buttons?: IterableEmbeddedMessageElementsButton[];
12+
readonly text?: IterableEmbeddedMessageText[];
13+
14+
constructor(
15+
title?: string,
16+
body?: string,
17+
mediaUrl?: string,
18+
mediaUrlCaption?: string,
19+
defaultAction?: IterableEmbeddedMessageDefaultAction,
20+
buttons?: IterableEmbeddedMessageElementsButton[],
21+
text?: IterableEmbeddedMessageText[]
22+
) {
23+
this.title = title;
24+
this.body = body;
25+
this.mediaUrl = mediaUrl;
26+
this.mediaUrlCaption = mediaUrlCaption;
27+
this.defaultAction = defaultAction;
28+
this.buttons = buttons;
29+
this.text = text;
30+
}
31+
32+
static fromDict(
33+
dict: Partial<EmbeddedMessageElementsDict>
34+
): IterableEmbeddedMessageElements {
35+
const title = dict.title;
36+
const body = dict.body;
37+
const mediaUrl = dict.mediaUrl;
38+
const mediaUrlCaption = dict.mediaUrlCaption;
39+
const defaultAction = dict.defaultAction
40+
? IterableEmbeddedMessageDefaultAction.fromDict(dict.defaultAction)
41+
: undefined;
42+
43+
const buttons = dict.buttons?.map((button) =>
44+
IterableEmbeddedMessageElementsButton.fromDict(button)
45+
);
46+
47+
const text = dict.text?.map((text) =>
48+
IterableEmbeddedMessageText.fromDict(text)
49+
);
50+
51+
return new IterableEmbeddedMessageElements(
52+
title,
53+
body,
54+
mediaUrl,
55+
mediaUrlCaption,
56+
defaultAction,
57+
buttons,
58+
text
59+
);
60+
}
61+
}
62+
63+
export interface EmbeddedMessageElementsDict {
64+
title?: string;
65+
body?: string;
66+
mediaUrl?: string;
67+
mediaUrlCaption?: string;
68+
defaultAction?: IterableEmbeddedMessageDefaultAction;
69+
buttons?: IterableEmbeddedMessageElementsButton[];
70+
text?: IterableEmbeddedMessageText[];
71+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export class IterableEmbeddedMessageText {
2+
/** The id of the text element */
3+
readonly id: string;
4+
/** The text of the text element */
5+
readonly text?: string;
6+
/** The type of the text element */
7+
readonly type?: string;
8+
9+
/**
10+
* Creates an instance of `IterableEmbeddedMessageText`.
11+
*
12+
* @param id - The id of the text element
13+
* @param text - The text of the text element
14+
* @param type - The type of the text element
15+
*/
16+
constructor(id: string, text?: string, type?: string) {
17+
this.id = id;
18+
this.text = text;
19+
this.type = type;
20+
}
21+
22+
/**
23+
* Creates an instance of `IterableEmbeddedMessageText` from a dictionary object.
24+
*
25+
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageText` instance.
26+
* @returns A new instance of `IterableEmbeddedMessageText` initialized with the provided dictionary properties.
27+
*/
28+
static fromDict(
29+
dict: Partial<EmbeddedMessageTextDict>
30+
): IterableEmbeddedMessageText {
31+
if (!dict.id) {
32+
throw new Error('id is required');
33+
}
34+
return new IterableEmbeddedMessageText(dict.id, dict.text, dict.type);
35+
}
36+
}
37+
38+
/**
39+
* An interface defining the dictionary object containing the properties for an embedded message text.
40+
*/
41+
export interface EmbeddedMessageTextDict {
42+
id: string;
43+
text?: string;
44+
type?: string;
45+
}

src/embedded/classes/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from './IterableEmbeddedManager';
22
export * from './IterableEmbeddedPlacement';
3+
export * from './IterableEmbeddedMessageElementsButton';
4+
export * from './IterableEmbeddedMessageElementsButtonAction';
5+
export * from './IterableEmbeddedMessageMetadata';

0 commit comments

Comments
 (0)