Last active
June 28, 2023 14:25
-
-
Save jasisk/6881d02be7fc8b1d8a06 to your computer and use it in GitHub Desktop.
Automatically "react" to your own messages in Slack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Think you're something special? Automatically "react" | |
* to your own Slack messages. | |
* | |
* Example: | |
* autoReact('crab') // automatically react with the crab emoji | |
* | |
* Related: http://slackhq.com/post/123561085920/reactions | |
* | |
**/ | |
function autoReact(emoji) { | |
if (!TS.emoji.isValidName(emoji)) { | |
throw new Error(emoji + ' is not a valid emoji'); | |
}; | |
TS.channels.message_received_sig.add(function (channel, msg) { | |
var id, rxn = {}; | |
id = TS.model.user.id; | |
if (!msg._rxn_key || msg.type !== 'message' || msg.user !== id) { | |
return; // iduncare | |
}; | |
rxn.name = emoji; | |
if (msg.subtype === 'file_share') { | |
rxn.file = msg.file.id; | |
} else { | |
rxn.channel = channel.id; | |
rxn.timestamp = msg.ts; | |
} | |
TS.api.call('reactions.add', rxn, function (ok, resp) { | |
if (!ok) { | |
console.error(resp.error || 'could not add reaction'); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you be able to write something similar that automatically attaches a certain emoji to all posts in a channel?