UNPKG

@shgysk8zer0/slack

Version:

An npm package for sending messages in Slack

42 lines (32 loc) 937 B
import { SlackBlock } from './block.js'; import { SlackInteractiveElement } from '../element/interactive.js'; import { createFactory } from '../functions.js'; export class SlackActionsBlock extends SlackBlock { #elements = []; constructor({ elements = [], id } = {}) { super({ id }); if (! Array.isArray(elements)) { throw new TypeError('elements must be an array.'); } else if (elements.length !== 0) { this.add(...elements); } } add(...elements) { const before = this.#elements.length; const count = this.#elements.push(...elements.filter(el => el instanceof SlackInteractiveElement)); if (count - before !== elements.length) { throw new Error('Error adding some elements.'); } return this; } toJSON() { return { ...super.toJSON(), elements: this.#elements, }; } static get TYPE() { return 'actions'; } } export const createSlackActionsBlock = createFactory(SlackActionsBlock);