Skip to content

Instantly share code, notes, and snippets.

@jasisk
Last active June 28, 2023 14:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasisk/6881d02be7fc8b1d8a06 to your computer and use it in GitHub Desktop.
Save jasisk/6881d02be7fc8b1d8a06 to your computer and use it in GitHub Desktop.
Automatically "react" to your own messages in Slack.
/**
*
* 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');
}
});
});
}
@charlieswoop
Copy link

Would you be able to write something similar that automatically attaches a certain emoji to all posts in a channel?

@tristan-mcdonald
Copy link

+1 to what charlieswoop said!

@varunchandak
Copy link

varunchandak commented Jul 26, 2019

+1 to what @charlieswoop said!

@TeaRex-coder
Copy link

+1 to what @charlieswoop said!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment