Last active
November 16, 2023 13:45
-
-
Save Spriz/97fb4a0ebe2ca56f79de79106e0ab5e9 to your computer and use it in GitHub Desktop.
This file contains 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
//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