Skip to content

Instantly share code, notes, and snippets.

@tsur
Last active September 2, 2016 09:33
Show Gist options
  • Save tsur/a7fe9df498b67b7b72701e491691c273 to your computer and use it in GitHub Desktop.
Save tsur/a7fe9df498b67b7b72701e491691c273 to your computer and use it in GitHub Desktop.
Slack breakfast bot seed
#!/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"
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