Created
March 5, 2018 10:14
-
-
Save lukaszlenart/fd1961d10d487b0e6e6f115c20836aba to your computer and use it in GitHub Desktop.
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
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