@shgysk8zer0/slack
Version:
An npm package for sending messages in Slack
43 lines (34 loc) • 837 B
JavaScript
import { SlackBlock } from './block.js';
import { SlackPlainTextElement } from '../element/plain-text.js';
import { createFactory } from '../functions.js';
export class SlackHeaderBlock extends SlackBlock {
#text;
constructor(text, { id } = {}) {
super({ id });
if (typeof text !== 'undefined') {
this.text = text;
}
}
get text() {
return this.#text;
}
set text(val) {
if (val instanceof SlackPlainTextElement) {
this.#text = val;
} else if (typeof val === 'string') {
this.text = new SlackPlainTextElement(val);
} else {
throw new TypeError('text must be a string or plain SlackPlainTextElement.');
}
}
toJSON() {
return {
...super.toJSON(),
text: this.#text,
};
}
static get TYPE() {
return 'header';
}
}
export const createSlackHeaderBlock = createFactory(SlackHeaderBlock);