-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to add Slack integration? #137
Comments
Hi @todbot If you don't mind, I started to actually hack this together. :) |
Hi @Skarlso, That's great news! Please let me know if you have any questions. I started looking into it before covid but the Slack API seemed pretty deep and it wasn't clear to me if it was even possible to do what I assumed everyone wanted (event on mention) |
Hey! I'll let you know when I know more. My initial research also led me to that. It looks like only bots are getting a mention event and users don't. But I'll figure something out. Maybe with the live chat thing... But I'll ask about structure for sure later on when I have my notes straight. 😊 |
@todbot hey. So I thought of this. There is no direct, simple way to a mention per the API. HOWEVER! There is a way to just simply respond to messages. I'm going to use the WebAPI event, message received. That has the text. The UI will take a comma separated list of things to look for in a message, just like you can set arbitrary words to get notification on in Slack, you can have a list like, Now, this could be further refined later to something like, run a different pattern on a different text mention, like, if somebody mentioned me by my userID ( which will be just the display text in Slack but passed along is the userID ) it's more important than someone writing down my name. This can be achieved with multiple triggers right now ofc, but later on could be combined into a single view. What say you? :) |
Hey that sounds like it could work. And could be much more useful than simple @mentions. (like "blink whenever 'gravitational wave' is mentioned" or whatever) |
Cool! I actually started adding a slack service and a form. But I can do the latter if you wish. :) |
Oh sure, if you feel comfortable enough moving around in the codebase, please try adding stuff! I just didn't want to inflict it upon you. :) |
Thanks, much appreciated. :) Humm, I don't know yet. :D I think I have the gist of it, but if I get stuck, I'll be sure to notify you. :) |
Sh*t. This still requires an App to be installed and running in some workspace. :( I misread this stuff. I thought a user could have a user token. But the user token is just there so the bot can act on the users behalf. A workspace or a community slack like gopher will never allow to install a bot from a user. :/ A user basically can't do anything. :(
This basically kills this whole process. If you can't get an app into the workspace, this won't work. Now. I will still add this as an RTM. ( the other option is running a server which Slack can call to ) Messages still can be received. But the bot basically needs to be in the channel. And this won't work for private conversations of course. :/ |
Hi, so I'm trying to debug this stuff. :) I'm trying to run it in Dev so I can see console output and things. but it comes up as a blank screen. Any ideas why? |
I think I don't call this out in the README well, but are you running both |
Uh... No... 😁 I'll try later today.
…On Tue, 14 Apr 2020, 18:05 Tod E. Kurt, ***@***.***> wrote:
I think I don't call this out in the README well, but are you running both npm
watch and npm run startdev at the same time?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#137 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABMUQVYYOEA6DETQBGZA4TRMSCVZANCNFSM4KXKNATA>
.
|
Ah worked! Thanks. I think I have something now. Going to test it. :) |
I got this to work somewhat by watching the Slack logs. Sorry @todbot I stole your code from your Edit: this works on macOS btw, you can probably change out the log path to your Slack's log if you're using other OS. Just replace const Tail = require('tail').Tail;
const Blink1 = require('node-blink1');
const SLACK_LOG = `${YOUR_HOME_FOLDER}/Library/Containers/com.tinyspeck.slackmacgap/Data/Library/Application Support/Slack/logs/webapp-console.log`;
const devices = Blink1.devices(); // returns array of serial numbers
let blink1 = null;
if (devices.length) {
blink1 = new Blink1();
}
function blink1TryConnect () {
if (blink1) {
return false;
}
devices = Blink1.devices();
if (devices.length) {
blink1 = new Blink1();
}
return true;
};
// Call blink1.fadeToRGB while dealing with disconnect / reconnect of blink1
function blink1Fade (millis, r, g, b, ledn){
blink1TryConnect();
if (!blink1) {
return "no blink1";
}
try {
blink1.fadeToRGB(millis, r, g, b, ledn);
} catch (err) {
blink1 = null;
return ""+err;
}
return "success";
};
function on () {
blink1Fade(500, 255, 0, 0);
}
function off () {
blink1Fade(500, 0, 0, 0);
}
let focused = false;
let log = new Tail(SLACK_LOG);
log.on('line', function (line) {
if (line.match(/\[FOCUS-EVENT\] Client window focused/g)) {
console.log('window focused');
focused = true;
off();
return;
}
if (line.match(/\[FOCUS-EVENT\] Client window blurred/g)) {
console.log('window blurred');
focused = false;
return;
}
if (line.match(/NEW_NOTIFICATION/g)) {
console.log('new noti');
if (focused === false) {
on();
} else {
off();
}
}
}); |
How would you get a hold of the slack log? How would this work on a slack which you don't control? |
Well I dug around Slack's source code to find their log path. I think on Windows it's in user's AppData folder. The log in question is the log of the Slack client app that's running on your computer. Mine is a copy downloaded from the Mac AppStore. As to your second question, I'm not quite sure what you mean by "Slack you don't control". If you're in a Slack workspace, and you have the Slack client app running, you will get notifications right? The app emits some logs when you get notifications and I'm just watching that log file. Hope this helps :) |
Ah you mean the mac client can log. Well, I don't use the app. I'm using the in browser version. :-) |
@Skarlso I reread the thread, it seems like you want to control the Blink(1) through some Slack command. Well my code doesn't work for that use case. Mine simply acts as an notification indicator to your own Slack client. I think it's still possible because there are 3rd party Slack clients that have almost full abilities of a normal user. Check this out: https://github.com/wee-slack/wee-slack. I don't know the details as to how exactly that works but the code is there. |
Yep that's exactly what I'm trying to do here #139. My only problem is that the server isn't starting up for some reason. I'll take a second look at it today. |
Hah I actually found my error... I might be able to pull this baby off. ;) |
It WORKS!!!!!!!!!!!!!!!!!! 🥳 🥳 |
Slack integration is now fully functional. I'll add some notes on how to create a classic slack app which has access to the Real Time Messaging system and what tokens to use and how. Also, need to add a slack bot user for that. After picking through a lot of documentation, it's actually quite easy. I tested it, and got a blinker reaction on a Keyword in a message. So it's possible to set up multiple rules for different keywords. An alert with Red blinking, or just my name mention with yellow blinking... etc. |
I added entries to the Notes about some clarification on how to use this integration. @todbot Is it all good now? :) |
Hi @Skarlso! This is incredible, thank you! I'm looking at it now and will start doing some test builds of it over the weekend. |
Thanks @todbot. :) As a side question... Are you going to pin to a version in eslint? Can I add 8 as language version and convert things to Or, for now, let's stick with the current context so refactoring can be done more easily later on as a whole? What do you think? :) |
@todbot Something that is not working atm is multiple slack Event sources. That's because there is only one connection to the bot. :/ if you create a new event source to the same bot, that will overtake the other one. In order to have multiple ones, you would need multiple bots. I don't think I can do anything about this I'm afraid. :/ |
Copy of issue todbot/blink1#275
Looks like it might be possible to add Slack integration, since IFTTT Slack channel doesn't support Slack event triggers. (But why? This may prevent us from adding it too)
Slack API: https://api.slack.com
Supported events: https://api.slack.com/events
Perhaps Blink1Control configuration is:
User inputs Web API auth token generated here: https://api.slack.com/web
User picks which events they want and what color patterns to trigger.
The text was updated successfully, but these errors were encountered: