Reputation: 7581
How can I allow a Slack Bot, implemented with Spring Boot, to delete a message?
The Spring Boot Slack Bot uses the simple-slack-api. When sending a deleteMessage the received reply is: cant_delete_message. So an authorisation issue.
The Slack Bot code is:
SlackSession session = SlackSessionFactory.createWebSocketSlackSession(slackToken);
session.connect();
SlackMessagePostedListener messagePostedListener = new SlackMessagePostedListener() {
@Override
public void onEvent(SlackMessagePosted event, SlackSession session) {
if (session.sessionPersona().getId().equals(event.getSender().getId())) {
return; // don't react on slack bot's own replies
}
SlackChannel channelOnWhichMessageWasPosted = event.getChannel();
String messageContent = event.getMessageContent();
SlackUser messageSender = event.getSender();
if( messageContent.startsWith( "secret")) {
session.sendMessage(event.getChannel(), "pssst: " + messageContent);
SlackMessageHandle handle = session.deleteMessage( event.getTimeStamp(), channelOnWhichMessageWasPosted);
logger.info( "Delete result : " + ((ParsedSlackReply) handle.getReply()).getErrorMessage());
} else { ... }
}
};
session.addMessagePostedListener(messagePostedListener);
Upvotes: 1
Views: 275
Reputation: 32698
Normally users can only delete their own message, not the messages of others. Except for admins and owners. This behavior can be set in the workspace settings.
If you want to be sure that your bot can delete message from others make sure its installed by an admin user and then use his access token (not the bot token).
Upvotes: 1