Package com.simplicite.util.tools
Class SlackTool
- java.lang.Object
-
- com.simplicite.util.tools.SlackTool
-
public class SlackTool extends java.lang.Object
Slack API toolbox (see https://https://api.slack.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SlackTool.SlackMessage
Slack message
-
Constructor Summary
Constructors Constructor Description SlackTool()
Default constructor using system admin grant'sSLACK_SERVICE
system parameter as settingsSlackTool(Grant g)
Constructor using grant'sSLACK_SERVICE
system parameter as settingsSlackTool(org.json.JSONObject settings)
Constructor using custom settings
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkWebhookSignature(Parameters params)
Check webhook signature (see https://api.slack.com/docs/verifying-requests-from-slack)java.util.Map<java.lang.String,java.lang.String>
getChannels()
Get channelsjava.lang.String
getChannelURL(java.lang.String name)
Get channel URLjava.lang.String
getClientId()
Get Slack API client IDjava.lang.String
getClientSecret()
Get Slack API client secretjava.lang.String
getDefaultChannel()
Get default channel namejava.lang.String
getDefaultChannelURL()
Get default channel URLjava.lang.String
getId()
Get Slack API application IDjava.lang.String
getSigningSecret()
Get Slack API signing secretboolean
isDebug()
Is in debug modevoid
postMessage(java.lang.String channelName, java.lang.String message)
Send a simple message to a channelvoid
postMessage(java.lang.String channelName, org.json.JSONObject message)
Send a message to a channel (you can use the SlackMessage helper sub-class or build your JSON object message manually)void
setApplicationId(java.lang.String id)
Set Slack API IDvoid
setClientId(java.lang.String clientId)
Set Slack API client IDvoid
setClientSecret(java.lang.String clientSecret)
Set Slack API client secretvoid
setDebug(boolean debug)
Set debug modevoid
setDefaultChannel(java.lang.String name)
Set default channel namevoid
setSigningSecret(java.lang.String signingSecret)
Set Slack API signing secret
-
-
-
Constructor Detail
-
SlackTool
public SlackTool()
Default constructor using system admin grant'sSLACK_SERVICE
system parameter as settings
-
SlackTool
public SlackTool(Grant g)
Constructor using grant'sSLACK_SERVICE
system parameter as settings- Parameters:
g
- Grant
-
SlackTool
public SlackTool(org.json.JSONObject settings)
Constructor using custom settings- Parameters:
settings
- Settings
-
-
Method Detail
-
setApplicationId
public void setApplicationId(java.lang.String id)
Set Slack API ID- Parameters:
id
- Application ID
-
getId
public java.lang.String getId()
Get Slack API application ID- Returns:
- Application ID
-
setClientId
public void setClientId(java.lang.String clientId)
Set Slack API client ID- Parameters:
clientId
- Client ID
-
getClientId
public java.lang.String getClientId()
Get Slack API client ID- Returns:
- Client ID
-
setClientSecret
public void setClientSecret(java.lang.String clientSecret)
Set Slack API client secret- Parameters:
clientSecret
- Client secret
-
getClientSecret
public java.lang.String getClientSecret()
Get Slack API client secret- Returns:
- Client secret
-
setSigningSecret
public void setSigningSecret(java.lang.String signingSecret)
Set Slack API signing secret- Parameters:
signingSecret
- Signing secret
-
getSigningSecret
public java.lang.String getSigningSecret()
Get Slack API signing secret- Returns:
- Signing secret
-
getChannels
public java.util.Map<java.lang.String,java.lang.String> getChannels()
Get channels- Returns:
- Channels
-
setDefaultChannel
public void setDefaultChannel(java.lang.String name)
Set default channel name- Parameters:
name
- Default channel name
-
getDefaultChannel
public java.lang.String getDefaultChannel()
Get default channel name- Returns:
- Default channel name
-
getChannelURL
public java.lang.String getChannelURL(java.lang.String name)
Get channel URL- Parameters:
name
- Channel name- Returns:
- Channel URL
-
getDefaultChannelURL
public java.lang.String getDefaultChannelURL()
Get default channel URL- Returns:
- Channel URL
-
isDebug
public boolean isDebug()
Is in debug mode- Returns:
- True if in debug mode
-
setDebug
public void setDebug(boolean debug)
Set debug mode- Parameters:
debug
- Debug mode?
-
postMessage
public void postMessage(java.lang.String channelName, java.lang.String message) throws APIException
Send a simple message to a channel- Parameters:
channelName
- Channel namemessage
- Text message- Throws:
APIException
-
postMessage
public void postMessage(java.lang.String channelName, org.json.JSONObject message) throws APIException
Send a message to a channel (you can use the SlackMessage helper sub-class or build your JSON object message manually)- Parameters:
channelName
- Channel namemessage
- JSON object message- Throws:
APIException
-
checkWebhookSignature
public boolean checkWebhookSignature(Parameters params)
Check webhook signature (see https://api.slack.com/docs/verifying-requests-from-slack)- Parameters:
params
- Request parameters- Returns:
- True if signature is valid
-
-