I had to implement a chat server for a project I'm working on and since I had never done this before, I used Slack's documentation as a roadmap and ended up re-implementing pretty much their whole API (I went a bit overboard I know).
I would like to open source this code but was wondering if it was legal for me to do so or would I be infringing on Slack's IP.
What are protected and protectable are Trademarks. So using the word 'Slack' in the name or anything that looks like it came from the Slack web site (see the recent "Open Trello" flare up) will cause you legal issues and should be avoided entirely.
The most interesting "middle" case is if you want to host third party integrations which work on your system and Slack's then you're going to get some push back. But again, caveat things like patents, being enough workalike (or my favorite phrase bug-for-bug compatible) is well trodden and has consistently been shown to be ok. (see the latest Keurig fiasco for that!)