If your business is using Talend for Data Integration and Slack for business communication, there is good value in integrating the two. Talend will enable Slack Users to connect with the information they need. Sending a message or sending a file to Slack, both can be achieved by using Talend.
Choosing a Global Software Development Partner to Accelerate Your Digital Strategy
To be successful and outpace the competition, you need a software development partner that excels in exactly the type of digital projects you are now faced with accelerating, and in the most cost effective and optimized way possible.
Here are two example scenarios to show how it’s done.
Sending messages to Slack via Talend.
Slack uses the chat.postMessage API to send messages to Slack channels.
In Talend, a tRest component is used for the API call.
The content-type here is application/json. The Authorization token provided should be a bearer authorization.
In the HTTP body – the instructions are written in json since we have selected application/json as our content type. The channel tag should have the channel ID of the Slack channel where the message is sent. The message tag should have the message you want to print in the channel. Additionally, the channel ID and message values are contextualized for better code management. Finally, Execute the job successfully.
Furthermore, Add a slack bot to the channels in Slack where you want the APIs to interact. In Slack, a bot is controlled programmatically via a bot user token that can access one or more of Slack’s APIs. A bot can post messages and upload files.
Here is a sample slack message from the tRest Component of a Talend Job.
Sending file to Slack via Talend.
The tSystem Component is used to send files from Talend to Slack. It is used to run shell commands from Talend.
Slack uses the files.upload API to upload files to Slack channels.
Create a shell script file -> slack_upload.sh
Use the following command:
#!/bin/bash curl -F file=@$1 -F channels=$2 -F title=$3 -H Authorization:<bearer_authorization_code> https://slack.com/api/files.upload
Dissecting the query:
- Curl lets you talk to the server by specifying the URL and the data you want to send.
- -F command issues a http request with form submission data.
- The parameters we have defined are: File – Path and name of the file to upload; Channel – Slack Channel; Title – Title of the Slack Message.
- -H acts as a header of a request.
- The authorization tag expects the Bearer token needed for authorization
- Finally the slack file upload API – files.upload is called.
In the tSystem component – execute the slack_upload.sh script.
sh <path to slack_upload.sh> <file_to_be_uploaded> <slack channel to be uploaded in> <title of the slack message>
sh /home/user/slack_upload.sh /home/user/test.txt C02GJSFCD0Q,CTK3A5PH8 dummyNote: You can specify more than one slack channel.
Sample output of the command:
In conclusion, Talend to Slack Integration is seamless and useful for automated communication.