Skip to content

Commit 1c56ff1

Browse files
author
Evan Greer
committed
feat: adds button class and associated classes
1 parent e121bc6 commit 1c56ff1

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { IterableEmbeddedMessageElementsButtonAction } from './IterableEmbeddedMessageElementsButtonAction';
2+
3+
/**
4+
* IterableEmbeddedMessageElementsButton represents a button in an embedded message.
5+
*/
6+
export class IterableEmbeddedMessageElementsButton {
7+
/** The ID for the embedded message button */
8+
readonly id: string;
9+
/** The title for the embedded message button */
10+
readonly title?: string;
11+
/** The action for the embedded message button */
12+
readonly action?: IterableEmbeddedMessageElementsButtonAction;
13+
14+
/**
15+
* Creates an instance of IterableEmbeddedMessageButton.
16+
*
17+
* @param id - The ID for the embedded message button.
18+
* @param title - The title for the embedded message button.
19+
* @param action - The action for the embedded message button.
20+
*/
21+
constructor(
22+
id: string,
23+
title?: string,
24+
action?: IterableEmbeddedMessageElementsButtonAction
25+
) {
26+
this.id = id;
27+
this.title = title;
28+
this.action = action;
29+
}
30+
31+
/**
32+
* Creates an instance of `IterableEmbeddedMessageButton` from a dictionary object.
33+
*
34+
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageButton` instance.
35+
* @returns A new instance of `IterableEmbeddedMessageButton` initialized with the provided dictionary properties.
36+
*/
37+
static fromDict(
38+
dict: Partial<EmbeddedMessageElementsButtonDict>
39+
): IterableEmbeddedMessageElementsButton {
40+
if (!dict.id) {
41+
throw new Error('id is required');
42+
}
43+
const action = dict.action
44+
? IterableEmbeddedMessageElementsButtonAction.fromDict(dict.action)
45+
: undefined;
46+
return new IterableEmbeddedMessageElementsButton(
47+
dict.id,
48+
dict.title,
49+
action
50+
);
51+
}
52+
}
53+
54+
/**
55+
* An interface defining the dictionary object containing the properties for the embedded message button.
56+
*/
57+
export interface EmbeddedMessageElementsButtonDict {
58+
id: string;
59+
title?: string;
60+
action?: IterableEmbeddedMessageElementsButtonAction;
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* IterableEmbeddedMessageElementsButtonAction represents an action defined as a response to user events
3+
* for an embedded message button.
4+
*/
5+
export class IterableEmbeddedMessageElementsButtonAction {
6+
/**
7+
* The type of iterable action
8+
* For custom actions, the type is `action://` prefix followed by a custom action name
9+
*/
10+
readonly type: string;
11+
12+
/**
13+
* The url for the action when the type is `openUrl`
14+
* For custom actions, data is empty
15+
*/
16+
readonly data?: string;
17+
18+
/**
19+
* Creates an instance of IterableEmbeddedMessageElementsButtonAction.
20+
*
21+
* @param type - The type of the action.
22+
* @param data - Optional data associated with the action.
23+
*/
24+
constructor(type: string, data?: string) {
25+
this.type = type;
26+
this.data = data;
27+
}
28+
29+
/**
30+
* Creates an instance of `IterableEmbeddedMessageElementsButtonAction` from a dictionary object.
31+
*
32+
* @param dict - The dictionary object containing the properties to initialize the `IterableEmbeddedMessageElementsButtonAction` instance.
33+
* @returns A new instance of `IterableEmbeddedMessageElementsButtonAction` initialized with the provided dictionary properties.
34+
*/
35+
static fromDict(
36+
dict: Partial<EmbeddedMessageButtonActionDict>
37+
): IterableEmbeddedMessageElementsButtonAction {
38+
if (!dict.type) {
39+
throw new Error('type is required');
40+
}
41+
return new IterableEmbeddedMessageElementsButtonAction(
42+
dict.type,
43+
dict.data
44+
);
45+
}
46+
}
47+
48+
/**
49+
* An interface defining the dictionary object containing the properties for the embedded message button action.
50+
*/
51+
export interface EmbeddedMessageButtonActionDict {
52+
type: string;
53+
data?: string;
54+
}

0 commit comments

Comments
 (0)