News

Talend and Slack Integration

Istock 960790462 (1)

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.

Here are two example scenarios to show how it’s done.

  1. 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.

    Trest

    Trest Comp

    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.

    Slack Message

  2. 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.

    Tsystem

    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:

    1. Curl lets you talk to the server by specifying the URL and the data you want to send.
    2. -F command issues a http request with form submission data.
    3. The parameters we have defined are: File – Path and name of the file to upload; Channel – Slack Channel; Title – Title of the Slack Message.
    4. -H acts as a header of a request.
    5. The authorization tag expects the Bearer token needed for authorization
    6. Finally the slack file upload API – files.upload is called.

     

    In the tSystem component – execute the slack_upload.sh script.

    Syntax –

    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 dummy
    Note: You can specify more than one slack channel.

    Sample output of the command:

    Slack Upload

In conclusion, Talend to Slack Integration is seamless and useful for automated communication.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Kaushik Kumar Sen

More from this Author

Subscribe to the Weekly Blog Digest:

Sign Up
Follow Us
TwitterLinkedinFacebookYoutubeInstagram