Skip to content

Instantly share code, notes, and snippets.

@Spriz
Last active November 16, 2023 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spriz/97fb4a0ebe2ca56f79de79106e0ab5e9 to your computer and use it in GitHub Desktop.
Save Spriz/97fb4a0ebe2ca56f79de79106e0ab5e9 to your computer and use it in GitHub Desktop.
//If inputData.rawMessage does not contain "just signed" - abort
if (!inputData.rawMessage.includes("just signed")) {
return;
}
const emojis = [
"rocket",
"success",
"tada",
"v",
"star",
"star-struck",
"fire",
"boom",
"party_blob",
];
// Randomly choose 2 to 5 emojis
const numberOfEmojis = Math.floor(Math.random() * 3) + 2;
const selectedEmojis = [];
for (let i = 0; i < numberOfEmojis; i++) {
const randomIndex = Math.floor(Math.random() * emojis.length);
selectedEmojis.push(emojis[randomIndex]);
}
async function reactToMessage(emoji) {
var response = await fetch("https://slack.com/api/reactions.add", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + inputData.slackAuthToken,
} /* */,
body: JSON.stringify({
channel: inputData.channelId,
name: emoji,
timestamp: inputData.timestamp,
}),
});
return response.json();
}
for (let i = 0; i < selectedEmojis.length; i++) {
await reactToMessage(selectedEmojis[i]);
}
callback(null, {
selectedEmojis: selectedEmojis,
message: inputData.rawMessage,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment