Permalink
Please sign in to comment.
Showing
with
192 additions
and 0 deletions.
- +12 −0 .editorconfig
- +1 −0 .gitignore
- +10 −0 .jscsrc
- +16 −0 package.json
- +44 −0 src/index.js
- +28 −0 src/models/manager.js
- +81 −0 src/models/meeting.js
| @@ -0,0 +1,12 @@ | ||
| + | ||
| +root = true | ||
| + | ||
| +[*] | ||
| +charset = utf-8 | ||
| +end_of_line = lf | ||
| +insert_final_newline = true | ||
| +indent_style = space | ||
| +indent_size = 4 | ||
| + | ||
| +[*.json] | ||
| +indent_size = 2 |
| @@ -0,0 +1 @@ | ||
| +node_modules/ |
10
.jscsrc
| @@ -0,0 +1,10 @@ | ||
| +{ | ||
| + "preset": "google", | ||
| + "disallowKeywords": ["with"], | ||
| + "disallowMultipleLineBreaks": null, | ||
| + "disallowMultipleVarDecl": null, | ||
| + "disallowSpacesInsideObjectBrackets": null, | ||
| + "requireCamelCaseOrUpperCaseIdentifiers": null, | ||
| + "requireCurlyBraces": null, | ||
| + "validateIndentation": 4 | ||
| +} |
16
package.json
| @@ -0,0 +1,16 @@ | ||
| +{ | ||
| + "name": "slack-project-manager", | ||
| + "version": "1.0.0", | ||
| + "description": "", | ||
| + "main": "src/index.js", | ||
| + "dependencies": { | ||
| + "botkit": "^0.0.4", | ||
| + "lodash": "^3.10.1" | ||
| + }, | ||
| + "devDependencies": {}, | ||
| + "scripts": { | ||
| + "test": "echo \"Error: no test specified\" && exit 1" | ||
| + }, | ||
| + "author": "Yagiz Nizipli", | ||
| + "license": "MIT" | ||
| +} |
44
src/index.js
| @@ -0,0 +1,44 @@ | ||
| +'use strict'; | ||
| + | ||
| +const config = { | ||
| + port: 3000, | ||
| + token: 'xoxb-17065016470-hFTAT0RNh0NkRSLBRStDZ7Nn' | ||
| +}; | ||
| + | ||
| +const Botkit = require('botkit/lib/Botkit.js'); | ||
| + | ||
| +const controller = Botkit.slackbot({ | ||
| + debug: false | ||
| +}); | ||
| + | ||
| + | ||
| +const ManagerModel = require('./models/manager'); | ||
| +const manager = new ManagerModel(); | ||
| + | ||
| + | ||
| +controller | ||
| + .hears(['start meeting'], 'ambient', (bot, message) => { | ||
| + let channelId = message.channel; | ||
| + | ||
| + if (manager.meetingExist(channelId)) | ||
| + return bot.say(message, | ||
| + 'Sorry, there is an existing meeting in this channel'); | ||
| + | ||
| + let meeting = manager.create(channelId); | ||
| + | ||
| + meeting | ||
| + .start(bot, message) | ||
| + .then(() => { | ||
| + console.log('Conversation ended. Destroying...'); | ||
| + | ||
| + meeting.destroy(channelId); | ||
| + }); | ||
| + }); | ||
| + | ||
| + | ||
| +const managerProcess = controller.spawn({ | ||
| + token: config.token | ||
| + }) | ||
| + .startRTM((err, bot, payload) => { | ||
| + if (err) return console.error('Error: ', err); | ||
| + }); |
| @@ -0,0 +1,28 @@ | ||
| +'use strict'; | ||
| + | ||
| +const Meeting = require('./meeting'); | ||
| +const _ = require('lodash'); | ||
| + | ||
| + | ||
| + | ||
| +class manager { | ||
| + constructor() { | ||
| + this.meetings = {}; | ||
| + } | ||
| + | ||
| + meetingExist(id) { | ||
| + return this.meetings && this.meetings[id]; | ||
| + } | ||
| + | ||
| + create(channelId) { | ||
| + let meeting = new Meeting(); | ||
| + this.meetings[channelId] = meeting; | ||
| + return meeting; | ||
| + } | ||
| + | ||
| + destroy(channelId) { | ||
| + this.meetings[channelId] = undefined; | ||
| + } | ||
| +} | ||
| + | ||
| +module.exports = manager; |
| @@ -0,0 +1,81 @@ | ||
| +'use strict'; | ||
| + | ||
| +const _ = require('lodash'); | ||
| + | ||
| + | ||
| + | ||
| +class meeting { | ||
| + constructor(channelId) { | ||
| + this.channelId = channelId; | ||
| + this.participants = [ | ||
| + { | ||
| + name: 'yagiz', | ||
| + id: '5' | ||
| + } | ||
| + ]; | ||
| + this.questions = [ | ||
| + 'What did you do yesterday?', | ||
| + 'What are you going to do today?', | ||
| + 'Did you encounter any problems?' | ||
| + ]; | ||
| + this.answers = {}; | ||
| + } | ||
| + | ||
| + | ||
| + /** | ||
| + * @private | ||
| + * @param {String} answer | ||
| + */ | ||
| + checkAnswers_(answer, convo) { | ||
| + | ||
| + switch (answer.text) { | ||
| + case 'stop': | ||
| + convo.say('Conversation terminated.'); | ||
| + convo.stop(); | ||
| + break; | ||
| + default: | ||
| + break; | ||
| + } | ||
| + | ||
| + } | ||
| + | ||
| + start(bot, message) { | ||
| + let that = this; | ||
| + | ||
| + return new Promise((resolve, reject) => { | ||
| + bot.startConversation(message, (err, convo) => { | ||
| + convo.say('Started'); | ||
| + | ||
| + _.forEach(that.participants, (participant) => { | ||
| + convo.say('Hello @' + participant.name + | ||
| + ', it is your turn now.'); | ||
| + | ||
| + that.answers[participant.id] = []; | ||
| + | ||
| + _.forEach(that.questions, (question, index) => { | ||
| + convo.ask(that.questions[index], (msg, convo) => { | ||
| + that.checkAnswers_(msg, convo); | ||
| + | ||
| + that.answers[participant.id].push({ | ||
| + question: question, | ||
| + answer: msg.text, | ||
| + createdAt: Date.now() | ||
| + }); | ||
| + | ||
| + convo.next(); | ||
| + }); | ||
| + }); | ||
| + | ||
| + convo.say('Thank you @' + participant.name); | ||
| + }); | ||
| + | ||
| + convo.on('end', (convo) => { | ||
| + resolve(); | ||
| + }); | ||
| + }); | ||
| + }); | ||
| + } | ||
| +}; | ||
| + | ||
| + | ||
| +module.exports = meeting; |
0 comments on commit
0f79a1f