Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bcorne committed May 18, 2015
1 parent fdfd804 commit ef4a027
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Simple Slack API

This library allows an aplication to connect to [Slack](http://www.slack.com/) to receive and send messages from any channel as if it were a slack client. The main purpose of this library is to build slack bots able to react to channel events without having to configure any web hook. For now this library has very limited features and is quite experimental.
This library allows an aplication to connect to [Slack](http://www.slack.com/) to receive and send messages from any channel as if it were a slack client.

The main purpose of this library is to build slack bots able to react to channel events without having to configure any web hook.


## Short example
Expand Down Expand Up @@ -28,22 +30,24 @@ session.connect();
### Listening to messages :

Slack messages can be retrieved by attaching a SlackMessageListener to the session provided by the factory :


```java
session.addMessageListener(new SlackMessageListener()
session.addMessagePostedListener(new SlackMessagePostedListener()
{
@Override
public void onSessionLoad(SlackSession slackSession)
{
// is called when the session is connected
}

@Override
public void onMessage(SlackMessage slackMessage)
{
// is called every time a message is sent on a subscribed channel
}
@Override
public void onEvent(SlackMessagePosted event, SlackSession session)
{
session.sendMessageOverWebSocket(session.findChannelByName("general"), "Message sent : " + event.getMessageContent(), null);
}
});
```
```

(Since v0.4.0, lambda friendly version)
```java
session.addMessagePostedListener((e, s)
-> s.sendMessageOverWebSocket(s.findChannelByName("general"), "Message sent : " + e.getMessageContent(), null));
```
### Message operation :

The SlackSession interface provides various methods to send/modify and delete messages on a given channel :
Expand All @@ -54,6 +58,19 @@ SlackMessageHandle updateMessage(String timeStamp, SlackChannel channel, String
SlackMessageHandle deleteMessage(String timeStamp, SlackChannel channel)
```

### Supported events :

The following events are handled :

* message post on a channel / group / to the bot
* message update on a channel / group / to the bot
* message delete on a channel / group / to the bot
* channel creation
* channel deletion
* channel archiving
* channel unarchiving
* channel renaming
* private group joining

## Full example :

Expand All @@ -67,16 +84,11 @@ public class Example

final SlackSession session = SlackSessionFactory.
createWebSocketSlackSession("authenticationtoken", Proxy.Type.HTTP, "myproxy", 1234, true);

session.addMessagePostedListener(new SlackMessagePostedListener()
session.addMessageListener(new SlackMessageListener()
{
@Override
public void onSessionLoad(SlackSession slackSession)
{
}

@Override
public void onMessage(SlackMessage slackMessage)
public void onEvent(SlackMessagePosted event, SlackSession session)
{
//let's send a message
SlackMessageHandle handle = session.sendMessage(slackMessage.getChannel(),
Expand Down Expand Up @@ -104,7 +116,6 @@ public class Example
});
session.connect();


while (true)
{
Thread.sleep(1000);
Expand Down

0 comments on commit ef4a027

Please sign in to comment.