Come join us on November 27-29, 2018 at the Gartner Application Strategies & Solutions Summit 2018 in Las Vegas, USA.
In this tutorial, we will follow the guideline for developing a plugin to develop our Slack Notification plugin. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable for more details steps.
1. What is the problem?
We want to send message to Slack to notify user when there is an assignment created for them in Joget Workflow.
2. How to solve the problem?
3. What is the input needed for your plugin?
To develop a Slack Notification plugin, we will consider providing the properties options similar to User Notification plugin.
4. What is the output and expected outcome of your plugin?
When an assignment is created for an user, a message with assignment link will send to his/her Slack account based on the configuration.
5. Are there any resources/API that can be reused?
6. Prepare your development environment
We need to always have our Joget Workflow Source Code ready and builded by following this guideline.
The following tutorial is prepared with a Macbook Pro and the Joget Source Code is version 5.0.1. Please refer to the Guideline for developing a plugin article for other platform commands.
Let's say our folder directory is as follows.
The "plugins" directory is the folder we will create and store all our plugins and the "jw-community" directory is where the Joget Workflow Source code is stored.
Run the following command to create a maven project in "plugins" directory.
Then, the shell script will ask us to key in a version number for the plugin and ask us for a confirmation before it generates the maven project.
We should get a "BUILD SUCCESS" message shown in our terminal and a "slack_notification" folder created in the "plugins" folder.
Open the maven project with your favourite IDE. I will be using NetBeans.
7. Just code it!
a. Extending the abstract class of a plugin type
Create a "SlackNotification" class under "org.joget" package. Then, extend the class with org.joget.apps.app.lib.UserNotificationAuditTrail class which is extends org.joget.plugin.base.DefaultAuditTrailPlugin abstract class. Please refer to Audit Trail Plugin. We will need to implement org.joget.plugin.base.PluginWebSupport interface class as well to provide a send test message button in plugin properties page. Please refer to Web Service Plugin.
b. Implement all the abstract methods
As usual, we have to implement all the abstract methods. We will using AppPluginUtil.getMessage method to support i18n and using constant variable MESSAGE_PATH for message resource bundle directory.
Now, we have to create a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is located at "/properties/slackNotification.json". Let us create a directory "resources/properties" under "slack_notification/src/main" directory. After creating the directory, create a file named "slackNotification.json" in the "properties" folder.
In the properties definition options file, we will need to provide options as below. Please note that we can use "@@message.key@@" syntax to support i18n in our properties options. Here, we can actually copy the properties options of User Notification plugin and modify from there. Please refer to userNotificationAuditTrail.json.
After completing the properties option to collect inputs, we can work on the main methods of the plugin which is execute method. But, since we extended UserNotificationAuditTrail class, we just need to override the sendEmail method which used to send out email by UserNotificationAuditTrail class.
In our plugin properties, we have a button to send test message. Let implement the webService method to provide an API to send test message.
c. Manage the dependency libraries of your plugin
We need to include "jsp-api" and "slack-webhook" libraries in our POM file.
d. Make your plugin internationalization (i18n) ready
We are using i18n message key in getLabel and getDescription method. We will use i18n message key in our properties options definition as well. Then, we will need to create a message resource bundle properties file for our plugin.
Create a directory, "resources/message", under "slack_webhook/src/main" directory. Then, create a "SlackWebhookTool.properties" file in the folder. In the properties file, add all the message keys and its label as below.
e. Register your plugin to the Felix Framework
Next, we will have to register our plugin class in the Activator class (Auto generated in the same class package) to tell the Felix Framework that this is a plugin.
f. Build it and test
Let's build our plugin. Once the building process is done, we will find a "slack_notification-5.0.0.jar" file created under "slack_notification/target" directory.
Then, let's upload the plugin jar to Manage Plugins. After uploading the jar file, double check that the plugin is uploaded and activated correctly.
Check the Slack Notification plugin is available in Plugin Default Properties.
Now, let us configure the Incoming Webhooks in Slack platform.
- Go to your_team.slack.com/services/new.
- Search for Incoming WebHook and click in
- Choose Channel to Post and press
Add Incoming WebHooks Integration
- Into Setup Instructions, you've a WebHook URL. This is the argument will use for the "Webhook URL" later. Then, copy it.
Configure the Slack Notification plugin. We can see the properties options are quite similar to User Notification plugin.
When test running a process, the message is received in Slack once a new assignment is created.
8. Take a step further, share it or sell it
You can download the source code from slack_notification_src.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/. (Coming Soon)