Skip to content

Commit

Permalink
adding reaction emoji feature
Browse files Browse the repository at this point in the history
It is now possible for the bot to automatically add a reaction
emoji to any message on any channel it has access.

Change-Id: I223b07a7a6b7d3d8ec84297a031d806cb3bbe7b3
  • Loading branch information
Benoit Corne committed Jul 24, 2015
1 parent b96aa98 commit df03acb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ apply plugin: 'maven-publish'

group = 'com.ullink.slack'
archivesBaseName = 'simpleslackapi'
version = '0.4.2-SNAPSHOT'
version = '0.4.3'


task javadocJar(type: Jar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface SlackSession

SlackMessageHandle sendMessageOverWebSocket(SlackChannel channel, String message, SlackAttachment attachment);

SlackMessageHandle addReactionToMessage(SlackChannel channel, String messageTimeStamp, String emojiCode);

SlackPersona.SlackPresence getPresence(SlackPersona persona);

void addchannelArchivedListener(SlackChannelArchivedListener listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,34 @@ public SlackMessageHandle updateMessage(String timeStamp, SlackChannel channel,
return handle;
}

@Override
public SlackMessageHandle addReactionToMessage(SlackChannel channel, String messageTimeStamp, String emojiCode)
{
SlackMessageHandleImpl handle = new SlackMessageHandleImpl(getNextMessageId());
HttpClient client = getHttpClient();
HttpPost request = new HttpPost("https://slack.com/api/reactions.add");
List<NameValuePair> nameValuePairList = new ArrayList<>();
nameValuePairList.add(new BasicNameValuePair("token", authToken));
nameValuePairList.add(new BasicNameValuePair("channel", channel.getId()));
nameValuePairList.add(new BasicNameValuePair("timestamp", messageTimeStamp));
nameValuePairList.add(new BasicNameValuePair("name", emojiCode));
try
{
request.setEntity(new UrlEncodedFormEntity(nameValuePairList, "UTF-8"));
HttpResponse response = client.execute(request);
String jsonResponse = CharStreams.toString(new InputStreamReader(response.getEntity().getContent()));
LOGGER.debug("PostMessage return: " + jsonResponse);
SlackReplyImpl reply = SlackJSONReplyParser.decode(parseObject(jsonResponse));
handle.setSlackReply(reply);
}
catch (Exception e)
{
// TODO : improve exception handling
e.printStackTrace();
}
return handle;
}

private HttpClient getHttpClient()
{
HttpClient client = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ullink.slack.simpleslackapi.impl;

import static org.assertj.core.api.Assertions.assertThat;

import com.ullink.slack.simpleslackapi.SlackPersona;
import org.junit.Test;
import com.ullink.slack.simpleslackapi.SlackAttachment;
Expand Down Expand Up @@ -64,6 +63,12 @@ public SlackMessageHandle updateMessage(String timeStamp, SlackChannel channel,
{
return null;
}

@Override
public SlackMessageHandle addReactionToMessage(SlackChannel channel, String messageTimeStamp, String emojiCode)
{
return null;
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public SlackMessageHandle updateMessage(String timeStamp, SlackChannel channel,
return null;
}

@Override
public SlackMessageHandle addReactionToMessage(SlackChannel channel, String messageTimeStamp, String emojiCode)
{
return null;
}

};
try
{
Expand Down

0 comments on commit df03acb

Please sign in to comment.