Last active
September 2, 2016 09:33
-
-
Save tsur/a7fe9df498b67b7b72701e491691c273 to your computer and use it in GitHub Desktop.
Slack breakfast bot seed
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
#!/usr/bin/env bash | |
# Set on "crontab -e" to run the bot every day at some specific time | |
# Load nvm | |
. ~/.nvm/nvm.sh | |
# Load bashrc | |
. $HOME/.bashrc | |
echo "Running nvm use stable" | |
nvm use stable | |
echo "Running script" | |
cd <absolute_path_to_bot> && node bot.js | |
echo "finish" |
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
import Bot from 'slackbots'; | |
// Provide the usernames you wanna emit the messages to | |
const users = []; | |
// const usersID = []; | |
// The alert message | |
const msg = ""; | |
// The bot settings | |
const botSettings = { | |
token: '', | |
name: '' | |
}; | |
// Emit a message to each user once bot has connected | |
const onStart = function(){ | |
users.forEach(username => bot.postMessageToUser(username, msg)); | |
} | |
// Check all user got the message and exit | |
const onMessage = function(message){ | |
if(message && message.username == settings.name) pendingACKMessages--; | |
if(!pendingACKMessages) process.exit(0); | |
} | |
// Kick off | |
(function main(){ | |
const bot = new Bot(botSettings); | |
bot.on('start', onStart); | |
bot.on('message', onMessage); | |
})(onStart, onMessage); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment