io.dangernoodle.slack.client.SlackClientSettings Maven / Gradle / Ivy
package io.dangernoodle.slack.client;
import java.util.HashMap;
import java.util.Map;
/**
* Configure the SlackClient
*
* @since 0.1.0
*/
public class SlackClientSettings
{
private String authToken;
private boolean dispatchMessageSubtypes;
private boolean filterSelfMessages;
private int heartbeat = 15;
private final Map pingArgs;
private boolean reconnect;
public SlackClientSettings(String authToken)
{
this.authToken = authToken;
this.reconnect = true;
this.dispatchMessageSubtypes = true;
this.pingArgs = new HashMap<>();
}
public boolean dispatchMessageSubtypes()
{
return dispatchMessageSubtypes;
}
/**
* Toggle dispatching message subtypes to individual handlers
*
* Default is true - if false, all messages will be dispatched to the
* message posted event observer.
*
*/
public SlackClientSettings dispatchMessageSubtypes(boolean dispatch)
{
this.dispatchMessageSubtypes = dispatch;
return this;
}
public boolean filterSelfMessages()
{
return filterSelfMessages;
}
/**
* Toggle automatic filtering of messages posted by the bot
*
* Default is true
*
*/
public SlackClientSettings filterSelfMessages(boolean filterSelfMessages)
{
this.filterSelfMessages = filterSelfMessages;
return this;
}
public String getAuthToken()
{
return authToken;
}
public int getHeartbeat()
{
return heartbeat;
}
public SlackClientSettings heartbeat(int heartbeat) throws IllegalArgumentException
{
if (heartbeat < 1)
{
throw new IllegalArgumentException("heartbeat must be greater then 0");
}
this.heartbeat = heartbeat;
return this;
}
/**
* Additional name/value pairs that will be sent with ping requests.
*/
public SlackClientSettings pingArg(String name, String value)
{
pingArgs.put(name, value);
return this;
}
public Map pingArgs()
{
// always a copy
return new HashMap<>(pingArgs);
}
public boolean reconnect()
{
return reconnect;
}
public SlackClientSettings reconnect(boolean reconnect)
{
this.reconnect = reconnect;
return this;
}
}