Mattermost is the most Slack-compatible open-source alternative. It offers channels, direct messages, threads, built-in bots, slash commands, webhooks, and a plugin system. The Community Edition is MIT-licensed and self-hostable — used by NASA, Uber, and the US DoD.
$docker run -d -p 8065:8065 mattermost/mattermost-team-edition