Enabling User Actions
Add interactive elements to your integration
By making use of the onMessage
hook and the sendIntegrationMessage
utility you can allow user's to trigger actions right from your integration in the overlay window.
To begin, you need to create a way for the user to trigger an action. In your handlebars template we can do this by adding a button that triggers an action "doSomething" on our component file.
On the component file, we then need to add a function that is run when the action doSomething
is triggered by a user clicking on the "Submit" button we created.
The sendIntegrationMessage
here will send the payload {action: 'Button Clicked'}
to the integration's onMessage
method implemented on the integration.js
file running on the server.
On the server, you should listen for the message coming from the component using the onMessage
hook.
The onMessage
implementation above simply responds back to the component with the message "Hello World!" with a server incremented counter appended to it.
After setting up your onMessage
function within the integration.js
file on the server, you will need to export the function so the Polarity Server is able to run it:
Last updated