Problem - You need to post message to your slack channel webhook using talend. This message could be something like sending a summary of your load job, its success or failure.
Solution - to post a message to slack one of the way is using payload.
payload={"channelname": "#yourchannelname", "username": "anyusernameyoucanput", "text": "message to be posted", "icon_emoji": ":ghost:"}'
you can then post this payload using below
curl -X POST --data-urlencode 'payload={"channelname": "#yourchannelname", "username": "anyusernameyoucanput", "text": "message to be posted", "icon_emoji": ":ghost:"}'
in Talend you can use below in tJava component to do above.
here there are some context.* (context variables used which you have to define in your job)
Once the context parameters are defined, you can run the job and if you have entered things correctly you should be able to post message to slack.
String strSlackPayload ="";
strSlackPayload += "{\"channel\": \"#";
strSlackPayload += context.slack_channel_name+"\", \"username\": \""+context.slack_user_name+"\"";
strSlackPayload += ", \"text\": \"";
strSlackPayload += "message to be sent";
strSlackPayload += "\", \"icon_emoji\": \":white_check_mark:\"}";
String line;
StringBuffer jsonString = new StringBuffer();
URL url = new URL(context.slack_webhook_url);
//escape the double quotes in json string
String payload=strSlackPayload;
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
writer.write(payload);
writer.close();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = br.readLine()) != null) {
jsonString.append(line);
}
br.close();
connection.disconnect();