Trigger > New Slack DM?

I'm desperately looking for a way to do some automation based on new direct messages on Slack.

I wonder if anyone already accomplished something similar or had an idea.

1 Like

I'm afraid that's not likely to ever happen...

Slack doesn't have any sort of system level API, so there's nothing to monitor.

On the other hand – it might be possible to do this with Slacks own API:

That's what I'd look into first if it was me.

As well as what Chris said above, another solution might be to leverage Slack's emailed notification of received DMs. But those emails are only sent out every 15 minutes (most frequent you can set it) so it will depend on how time-sensitive your automations will be.

1 Like

One way you might be able to accomplish what you want is to utilize the web version of slack. If I wanted to do something like what you describe I would use my Google chrome extension to automatically run macros on specific pages

How To Trigger Macros Automatically From Google Chrome

Then I would develop a macro that gets triggered on Slack that checks the interface for new DMs.

The JavaScript would run in a loop with a delay between each check. Then if something actionable is found I could make an ajax call back out to Keyboard Maestro using the same Web Server functionality that the previously mentioned Chrome extension makes use of.

1 Like

Sorry for the delay and thank you all for your replies.

Slack API/ APP is not an option for me because is blocked from my organisation,

I tried emailed notification a while ago but the delay it's too high.

I think the web version of Slack is probably the right way to do it alright, I know how to get text from Safari / click etc but I'm not sure how to manage this though, seems to complex (problem exposed here)

I never used KM OCR before, perhaps I could OCR a specific part of the screen and search for a number next to the name.

Right-Click on the code in the dev window and copy as JS Path

You'll get something that looks a bit like this:

document.querySelector("#post_5 > div > div.topic-body.clearfix")

Post it here, so we can see it.

I suspect it won't be that simple, but it's a start.

From the Safari console, that's seems to return nothing unless I'm going this wrong.

I managed to get the number of unread message but I can't tell from who and how to action/reply to it, probably too much work.

tell application "Safari"
	
	set unreadmessage to do JavaScript "document.getElementsByClassName('p-channel_sidebar__badge c-mention_badge c-mention_badge--black')[0].innerHTML;" in tab 2 of window 1
	
end tell
Result:
"2"

I just put up a demo of a macro that watches a web page for a change. You could take this and modify it to monitor for new DMs in Slack and then have a macro triggered based on that.

Demo Video

Macro Screenshot

Macro File

Monitor page for change.kmmacros (41.9 KB)

2 Likes