showModal(), and the submit arrives as a second interaction with kind: 'modal'.
New in 0.4.0. Read Buttons and selects first: a modal is one of the three answers to a click.
Open a modal
showModal(def) is a terminal response, like ack() and ephemeral(). It validates def locally with assertModal() before anything is encrypted, and a bad definition rejects with a CloakComponentError. A second response on the same interaction rejects with a CloakClientError whose source is 'interaction'.
ModalDefinition
short is a single line. paragraph is a multi-line box. The clicker’s app enforces required, minLength, and maxLength before it submits.
Receive the submit
The submit arrives as a freshinteraction:
ack() is the right answer when there is nothing to say back.
Cancelling the modal sends nothing. Your bot is not told, and there is nothing to clean up: the original click was already answered by showModal().
Tie the submit to the click
parentId is how you connect the form to whatever the button was about. The cheapest pattern is to carry the subject in the modal’s customId itself, since it comes back verbatim.
parentId on the submit. Expire entries after 15 minutes, because that is when the server forgets the click.
What a modal cannot do
- It cannot be posted on its own. It is always the answer to a click.
- It carries text inputs only. There are no selects or buttons inside a modal.
- It cannot pre-fill from anything but
value. - It is not stored anywhere. Reloading the app while a modal is open dismisses it, and nothing arrives at your bot.
Next
Buttons and selects
The click that opens a modal, and the other two answers.
Approval bot
A modal collects a denial reason in a complete bot.
Cards and embeds reference
ModalDefinition, assertModal(), and every cap.Types
The full
Interaction shape.