[Bonus Exercise] Add a new module to your manifest: trigger
At this point, you can already call external APIs and was able to work with different UI Kit components. Congratulations!
For this exercise, we’ll work with components that reside behind the scenes. We’ll add a new module to our app and listen to events that happen to the product; in this use case, we are looking out for new work items being created on Jira.
Add new trigger module to your manifest file
Yes, that is correct. We can add modules to our existing manifest without going through forge create all the time.
-
Go to your Forge CLI and run the
forge module addcommand to add a new trigger.If your Forge tunnel is still running, stop it by pressing
CTRL + Cbefore calling this commandforge module addSelect the following options
? Select a product Trigger ? Select a module trigger - Run a Forge function in response to Atlassian product events ? Module key product-trigger ? Function key product-trigger-fnThis will update your
manifest.ymlfile to add the new trigger listening for the Jira issue created eventtrigger: - key: product-trigger function: product-trigger-fn events: - avi:jira:created:issue filter: ignoreSelf: false expression: event.issue.fields.summary != nullThe function handler has been wired for us
function: - key: resolver handler: index.handler - key: product-trigger-fn handler: product-trigger.runThe necessary permission scope has been added, too!
permissions: ... scopes: [ read:jira-work ] -
Verify the function that your trigger will call. The
forge module addcommand has already created the new filesrc/product-trigger.jswhich contains the functionexport const run = (event) => { console.log('Received product event', JSON.stringify(event)); };
Test if the product trigger is being called
-
Deploy your changes. Given that we updated the permissions, we need to approve the major version bump by adding
--approve MAJOR VERSION_RULEforge deploy --approve MAJOR_VERSION_RULE -
Since there’s a change in the permissions, we need to upgrade the installation, too.
forge install --upgrade -
Run the tunnel to see the logs
forge tunnel -
Create a new work item and verify that the tunnel’s console printed out our logs.