-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edcf32b
commit 5ca90cc
Showing
2 changed files
with
42 additions
and
121 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +0,0 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const axios = require('axios'); | ||
const qs = require('qs'); | ||
var unassignedUsers; | ||
|
||
router.post('/', async (req, res, next) => { | ||
|
||
const { token, text, trigger_id } = req.body; | ||
const assignee = await roundRobin(); | ||
console.log(assignee); | ||
const name = 'Sawyer'; | ||
if (token === process.env.SLACK_VERIFICATION_TOKEN) { | ||
console.log('sendConfirmation'); | ||
axios.post('https://slack.com/api/chat.postMessage', qs.stringify({ | ||
token: process.env.SLACK_AUTH_TOKEN, | ||
channel: assignee, | ||
text: `Bzz! Bzz! Hey, you've been assigned an email`, | ||
attachments: JSON.stringify([{ | ||
"text": "Subject", | ||
"fallback": "Sorry you were unable to reply", | ||
"callback_id": "wopr_game", | ||
"color": "#FEE224", | ||
"attachment_type": "default", | ||
"actions": [ | ||
{ | ||
"name": "reply", | ||
"text": "Reply", | ||
"type": "button", | ||
"value": "reply" | ||
} | ||
] | ||
} | ||
]), | ||
})).then((result) => { | ||
console.log('sendConfirmation: %o', result.data); | ||
}).catch((err) => { | ||
console.log('sendConfirmation error: %o', err); | ||
console.error(err); | ||
}); | ||
} | ||
|
||
}); | ||
|
||
// Take in a user list and | ||
async function roundRobin() { | ||
if (unassignedUsers === undefined || unassignedUsers.length == 0) { | ||
// Reset unassignedUsers! | ||
const channelID = 'CBUAADA1Y'; | ||
const tokenWithChannel = { | ||
token: process.env.SLACK_AUTH_TOKEN, | ||
channel: 'CBUAADA1Y' | ||
}; | ||
try { | ||
console.log((await axios.post('https://slack.com/api/channels.info', qs.stringify(tokenWithChannel))).data.channel.members); | ||
unassignedUsers = (await axios.post('https://slack.com/api/channels.info', qs.stringify(tokenWithChannel))).data.channel.members; | ||
return getTheUser(); | ||
} catch (error) { | ||
console.log('error', error); | ||
} | ||
} else { | ||
return getTheUser(); | ||
} | ||
// Do the Round Robin: | ||
|
||
}; | ||
|
||
function getTheUser() { | ||
const user = unassignedUsers[Math.floor((Math.random() * unassignedUsers.length) + 1)]; | ||
console.log('user', user); | ||
// unassignedUsers.remove(user); | ||
if (unassignedUsers.length === 1) { | ||
unassignedUsers = ''; | ||
return unassignedUsers[0]; | ||
} | ||
unassignedUsers = unassignedUsers.filter(function(el) { | ||
return el !== user; | ||
}) | ||
|
||
console.log('user: ', user); | ||
|
||
console.log('Unassigned: ', unassignedUsers); | ||
return user; | ||
} | ||
|
||
const msg = { | ||
"text": "Hi friend! Bzz Bzz. You've been assigned an email!", | ||
"attachments": [ | ||
{ | ||
"text": "Choose something you need help with:", | ||
"fallback": "You are unable to choose a task", | ||
"callback_id": "wopr_game", | ||
"color": "#3AA3E3", | ||
"attachment_type": "default", | ||
"actions": [ | ||
{ | ||
"name": "qa", | ||
"text": "Question/Answer", | ||
"type": "button", | ||
"value": "qa" | ||
}, | ||
{ | ||
"name": "code", | ||
"text": "Code Snippet", | ||
"type": "button", | ||
"value": "code" | ||
}, | ||
{ | ||
"name": "url", | ||
"text": "URL", | ||
"type": "button", | ||
"value": "url" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
|
||
module.exports = router; | ||