Arpit Mohan
CTO, Bicycle.ai
21/10/2016
robot.hear /hello|hi$/i, (res) ->
response = ""
helloResponses = robot.brain.get('helloResponses') * 1 or 0
if helloResponses > 1
res.reply "Stop it already!"
#Resetting the count here. Ideally, this key should be reset every hour or so.
robot.brain.set 'helloResponses', 0
else
res.reply "Howdy there! How can I help?"
robot.brain.set 'helloResponses', helloResponses+1
Sample Code for the hello command
robot.hear /gitlab build (.*)$/i, (res) ->
res.send "Building ..."
project_name = res.match[1]
gitlab_ci_token = process.env.GITLAB_CI_TOKEN
res.send "Will build #{project_name} using key #{gitlab_ci_token}"
res.http("https://code.usefilter.com/api/v3/projects?private_token=#{gitlab_ci_token}")
.header('Accept', 'application/json')
.get() (err, http_res, body) ->
if err
res.send 'Sorry. Unable to fetch the list of projects from Gitlab'
return
for project in JSON.parse body
if project.name.toLowerCase() is project_name.toLowerCase()
project_found = true
project_id = project.id
res.send "Found project with ID: #{project.id}"
Sample code for the build command