diff --git a/README.md b/README.md index 27b4079..924a705 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,11 @@ into both of those. `#admin` is where `/admin` commands will go. * Grant the user admin privileges * Log in with the user on your browser (by visiting .slack.com) * Visit https://.herokuapp.com/install-inviter?team= -- the URL will be displayed the first time you try to accept a user anyway. + +### Welcome message to new users + +The `WELCOME_MESSAGE_TEXT` config var controls what message is sent to the new users when they join. By default it says: +`Welcome! Review the ${cocTxt} before participating in the community.` + +To disable the welcome message, set the config var `SEND_WELCOME_MESSAGE` to `FALSE`. + diff --git a/app.json b/app.json new file mode 100644 index 0000000..f7d367d --- /dev/null +++ b/app.json @@ -0,0 +1,23 @@ +{ + "name": "Wheelie Slack App", + "description": "Wheelie is a Slack App originally written for WeAllJS.com.", + "repository": "https://github.com/WeAllJS/wheelie-slack-app", + "keywords": ["node", "express", "slack", "bot"], + "env": { + "SEND_WELCOME_MESSAGE": { + "description": "If the value of is 'FALSE', no message will be sent to new members when they join " + }, + "WELCOME_MESSAGE_TEXT": { + "description": "A message that will be send to new members once they join the group" + }, + "SLACK_CLIENT_ID" : { + "description": "" + }, + "SLACK_CLIENT_SECRET" : { + "description": "" + }, + "VERIFICATION_TOKEN" : { + "description": "" + } + } +} diff --git a/lib/events/team_join.js b/lib/events/team_join.js index fb4c320..e218525 100644 --- a/lib/events/team_join.js +++ b/lib/events/team_join.js @@ -1,4 +1,22 @@ +const slack = require('slack') +const bluebird = require('bluebird') +const chat = bluebird.promisifyAll(slack.chat) + +const cocTxt = process.env.COC_URL ? `<${process.env.COC_URL}|Code of Conduct>` : 'Code of Conduct' +const welcome_message_text = process.env.WELCOME_MESSAGE_TEXT || `Welcome! Review the ${cocTxt} before participating in the community.` +const send_welcome_message = process.env.SEND_WELCOME_MESSAGE === 'FALSE' ? false : true + module.exports = (data, cb) => { console.log('new user joined team: ', data) - cb() + if (!send_welcome_message || !welcome_message_text) { + return cb() + } + chat.postMessageAsync({ + token: data.token, + channel: data.user.id, + text: welcome_message_text + }).then(() => { + return cb() + }) } + diff --git a/package.json b/package.json index 8105823..fcda495 100644 --- a/package.json +++ b/package.json @@ -20,5 +20,9 @@ }, "engines": { "node": "5.9.1" + }, + "devDependencies": { + "eslint": "^3.8.1", + "eslint-plugin-react": "^6.4.1" } }