Buttons are interactive components that can be used for custom actions, links, or premium features. The Button type is a union of CustomButton, LinkButton, and PremiumButton.
- CustomButton: Requires a
custom_id and a style from ButtonStyleTypes (PRIMARY, SECONDARY, SUCCESS, or DANGER). Used for handling interaction events. - LinkButton: Requires a
url and uses ButtonStyleTypes.LINK. - PremiumButton: Requires a
sku_id and uses ButtonStyleTypes.PREMIUM.
All buttons can optionally include an emoji and a label (except for Link and Premium buttons which have specific requirements).
// Example of a Custom Button
const myButton: Button = {
type: MessageComponentTypes.BUTTON,
custom_id: 'my_action_id',
style: ButtonStyleTypes.PRIMARY,
label: 'Click Me'
};
// Example of a Link Button
const linkButton: Button = {
type: MessageComponentTypes.BUTTON,
style: ButtonStyleTypes.LINK,
url: 'https://example.com',
label: 'Visit Website'
};