paint-brush
How to Force Slack to Make Your User Appear Onlineby@andrewarrow
367 reads
367 reads

How to Force Slack to Make Your User Appear Online

by Andrew ArrowJuly 20th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to get the green dot to turn on for slack users with a headless browser because their API just won't allow it.
featured image - How to Force Slack to Make Your User Appear Online
Andrew Arrow HackerNoon profile picture

It all started when I lost access to a slack network I was on. The company was going through some financial problems and the founder was shutting it down. It wasn't personal but all of a sudden I was removed from the slack network and I missed it. I missed the channel where I would post a nice little update of everything I did and get rockets, confetti, 100% or fire emoji responses + some actual english "wow!" or "that's great!" replies.


So I asked Chat-GPT for a good name for this project and together we created synapse-system. I had modest dreams. I dreamed I could use slack's api to post as two fake users I created: Fred Clark and Jenny Wey:


Fake names, fake AI generated photos, very sorry if one of these people looks exactly like you or has your name it was not on purpose. I was able to post as them with the endpoint https://slack.com/api/chat.postMessage pretty easily after some understanding of the scope's I needed and user_tokens vs bot_tokens. But something about Fred and Jenny not being "online" really bugged me. I wanted their green dots.


But no problem I thought. There is https://api.slack.com/methods/users.setPresence available and it even returns me a 200 OK when I call it with the user's token. I wrote into slack customer service and got: "It sounds like you may be trying to force the force the presence for a user to be active. However, in the Usage info section of the users.setPresence API doc, it states to Consult the presence documentation which is linked to the following User presence and status page: https://api.slack.com/docs/presence-and-status There's no way to force a user status to active."


So, what they are saying is this setPresence method, you can use it to turn the green dot off, but not on. The only option other than off is "auto" which means automatically turn it on when the user comes online via a slack client. Ah ha! Websockets, no problem I can do this.


They have Socket Mode and even a laugh-in reference joke socket-to-me article. I was able to make my app level token and get back an wss://myunique.slack.com/ws url and connecting to it was fine. I got back the hello message. But all I have is an app level token. There is no way to use socket mode with a user token and come "online."


They used to have Real Time Messaging but this is gone now and replace with socket mode where you can't send real time messages. Shrug. But whatever. This couldn't stop me. My green dots needed to come alive. I was left with just one option: cookie auth and run the same javascript the web client is running.


I learned a lot about cookies! And how chrome uses sqlite to store them but encrypts them. Neither chrome or firefox has an easy way to export ALL the cookies for a domain. You can delete en masse, but you can't export en masse. But in safari you can! My first attempt was using chromedp's cookie example. I took my exported safari cookie file and parsed it into the format chromedp wanted but it never compiled. Sigh. I was told I needed to look at the real deals: Puppeteer or Selenium. I'm not the biggest nodejs fan. When I see npm install I usually look for something else first. Sorry js fans! So Selenium it was.


What is going on here? They have every language BUT go? I did find github.com/tebeka/selenium but it only runs on linux. I breifly went to Lima because I had just read about it on hackernews! But this wasn't what I wanted. I wanted the green dots on but no containers running. I went with python.


options = Options()
options.profile = '/path/to/profile/jenny'
options.add_argument('-headless')
browser = webdriver.Firefox(options=options)
browser.get('https://app.slack.com/client')
time.sleep(26)
browser.quit()


So you can run: /Applications/Firefox.app/Contents/MacOS/firefox --profilemanager


And setup profiles for jenny and fred! Log in as them once. And now with a small headless firefox process running, finally, green dots:


I do have an open bounty for how to fix a deprecation warning I get, but hey it works. I'm using it. Where does synapse-system go from here? I'm not sure. I think I'll pause here for a bit and think it over. Do I really want fred and jenny to make openai requests and start acting like real co-workers? Maybe? For now I just love seeing them online. Watch the green dots on youtube. Or below.

Also published here.