Author: Shyam Kulkarni
Creating a Slack App:
For creating a Slack App, navigate to the following URL: https://api.slack.com
Now, on the webpage, you can see the option for creating an app.
Click on Create New App.
In the following dialog box that appears, choose “From an app manifest.”
Now, we need to pick up a workspace for developing our app.
In this POC, we will create a new workspace. So, you can click on “Sign in to a different workspace,” as shown in the above image.
Following are the steps required to create a new workspace.
- Enter your email address and click sign in with email.
Once logged in, you can see the following option to create a new workspace. So, Click on “Create Another workspace.” Then further, click on “Create a Workspace.”
Now, Start entering the details as depicted in the below images:
You can skip this step 2.
Enter your custom slack-channel name:
You can skip this step 3 and then further click on Skip Step to skip without inviting.
Then click on Open Slack, and you will be able to see a new workspace is created.
Thus, we have created a new workspace.
Now, head over to your browser, where you need to pick up a workspace to develop an app.
From the dropdown, select the workspace you’ve just created and click Next.
Now, enter the below snippet into your YAML section: [You may choose to give a different display-name for your app ]
Now, review the summary.
Now, you will be redirected to the page which will have your app information.
Further, we need to install your app to the workspace, so click on Install to Workspace.
In the webpage that appears, click on Allow.
Hence, you will get a Success Message.
Now, scroll down on the same page, and you will be able to see the App Credentials section.
Copy client ID and client secret and keep it for future purposes. We will need it while configuring in mule application.
Configuring Mule Application to Send Messages to Slack:
Step 1: Start Anypoint Studio and create a new project named “mule-slack-integration-poc”.
Step 2: Create a flow “mule-slack-integration-poc-flow” and configure it as follows:
i.) Add a Listener and set its display name to “8082 : /send-message”
ii.) Set its path to “/send-message”
iii.) Now, head over to connector configuration and click on the green plus icon.
iv.) Set the protocol to HTTPS and set the port to 8082.
v) Now, we will create a keystore.jks file.
For that, execute the below command in CMD:
|keytool -genkeypair -keyalg RSA -alias mule-demo -keystore keystore.jks|
-storetype jks -keypass pass1234 -storepass pass1234
vi.) Copy the keystore.jks file into src/main/resources.
vii.) Now, navigate to the TLS tab in the HTTP_Listener_Configuration and add the Keystore configuration.
viii.) Add a Transform Message which will be used for setting the channel name and message to be sent to the slack channel.
Add the below data weave script:
text: “Welcome to the Mule Universe!”
ix.) Now, for adding a slack connector, click on Search in Exchange in the Mule palette and search for the slack connector. [ Make sure that you add the non Community version of the connector ]
x.) Add a Send Message component from the Slack Connector module and configure it as follows:
Add the Client ID and Client Secret, which we have copied earlier into Consumer Key and Consumer Secret, respectively.
Copy “channels:read chat:write:bot” into Scope section.
xi.) Now, Add a Transform Message and Logger for printing payload:
Step 3: Now, Run the application after it gets deployed; Go to your browser, and type in the following url:
You will be redirected to the following page: Then Click on Allow.
You will get the following response: “Successfully retrieved access token.”
Step 4: Now, In the new tab, enter this URL:
You will get the following response, as well as the message, which could be seen in your slack channel.