simple-slack-api
simple-slack-api copied to clipboard
Send message as 'slackbot'
Is it possible to post message as slackbot ? My intention here is, when a new user logs in slack shows only slackbot and slack related tutorial. I also want to show details regarding my custom bot usage. I thought since slackbot is the first DM which user gets, sending as slackbot could serve the purpose. Is there a better way to perform this? How can we do that?
I have a registered listener for help commands called, HelpListener. This is the pertinent section of code that I use to send a welcome message to whoever joins a channel.
In the BotWelcome.sendWelcomeMessage
function I also save the username of the person welcomed so I don't re-welcome them.
public class HelpListener implements SlackMessagePostedListener {
@Override
public void onEvent(SlackMessagePosted event, SlackSession session) {
// Filter out the bot's own messages or messages from other bots
if (session.sessionPersona().getId().equals(event.getSender().getId()) || event.getSender().isBot()) {
return;
}
if (event.getMessageSubType() == SlackMessagePosted.MessageSubType.CHANNEL_JOIN
|| event.getMessageSubType() == SlackMessagePosted.MessageSubType.GROUP_JOIN) {
// Send a welcome message (will not re-send if already sent)
BotWelcome.sendWelcomeMessage(session, event.getChannel(), event.getSender());
// No need to continue, so return
return;
}
processMessageEvent(session, event);
}
}