-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrummasters.js
33 lines (32 loc) · 1.15 KB
/
scrummasters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const teamupCalendarKey = 'ks1c2vhnot2ttfvawo'
const teamupToken = process.env.HUBOT_TEAMUP_TOKEN
module.exports = (robot) => {
robot.error(function (err) {
robot.logger.error(err)
robot.send(`Error while running scrummaster bot: ${err}`)
})
robot.hear(/scrum(\s|-)?master(s)?/gi, (res) => {
const dateString = new Date().toISOString().slice(0, 10)
robot.http(`https://api.teamup.com/${teamupCalendarKey}/events?startDate=${dateString}&endDate=${dateString}`)
.headers({'Teamup-Token': teamupToken})
.get()((err, response, body) => {
if (err) {
robot.emit('error', `problem getting scrummaster: '${err}'`)
return
}
let parsedBody = {}
try {
parsedBody = JSON.parse(body)
} catch (e) {
robot.emit('error', `problem parsing '${body}' as JSON`)
return
}
if (typeof parsedBody.events === 'undefined' || parsedBody.events.length === 0) {
robot.emit('error', `scrummasters not found: '${body}'`)
return
}
const scrummaster = parsedBody.events[0].title
res.send(`^ ${scrummaster}`)
})
})
}