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 ]
display_information:Ā name: Mule-Slack-App features: Ā Ā bot_user: Ā Ā Ā Ā display_name: Mule-Slack-App Ā Ā Ā Ā always_online: trueo auth_config: Ā Ā redirect_urls: Ā Ā Ā Ā – https://localhost:8082/callback Ā Ā Ā Ā – https://0.0.0.0:8082/callback Ā Ā Ā Ā – https://127.0.0.1:8082/callback Ā Ā scopes: Ā Ā Ā Ā bot: Ā Ā Ā Ā Ā Ā – chat:write Ā Ā Ā Ā Ā Ā – channels:read Ā Ā Ā Ā Ā Ā – incoming-webhook settings:Ā Ā org_deploy_enabled: false Ā Ā socket_mode_enabled: false Ā Ā token_rotation_enabled: false |
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:
%dw 2.0 output application/json — { Ā Ā Ā Ā Ā Ā Ā Ā channel: “slack-demo”, Ā Ā Ā Ā Ā Ā Ā Ā 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:
%dw 2.0 output application/json — payload |
Step 3: Now, Run the application after it gets deployed; Go to your browser, and type in the following url:
https://localhost:8082/authorize
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:
https://localhost:8082/send-message
You will get the following response, as well as the message, which could be seen in your slack channel.