Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszlenart/fd1961d10d487b0e6e6f115c20836aba to your computer and use it in GitHub Desktop.
Save lukaszlenart/fd1961d10d487b0e6e6f115c20836aba to your computer and use it in GitHub Desktop.
robot.listen(
(msg) ->
# catch all text messages and unhandled
if msg.text and msg.done == false
# remove bot's name
if msg.text.toLowerCase().indexOf(robot.name) == 0
regex = new RegExp "^#{robot.name}", 'ig'
msg.text.replace(regex, '').trim()
else if msg.text.toLowerCase().indexOf("@#{robot.name}") == 0
regex = new RegExp "^@#{robot.name}", 'ig'
msg.text.replace(regex, '').trim()
else
false
else
false
(res) ->
robot.logger.info "Sending to Watson: #{res.match}"
conversation.message(
input:
text: res.match
workspace_id: config.workspace_id
,
(err, response) ->
# handle response
...
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment