Created
July 19, 2018 08:40
-
-
Save mike-neck/521a55002b23371e38d756415ee8caa9 to your computer and use it in GitHub Desktop.
AWS Translate を使って翻訳
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
// Description: | |
// Utility commands surrounding Hubot uptime. | |
// | |
// Commands: | |
// ping - Reply with pong | |
// echo <text> - Reply back with <text> | |
// time - Reply with current time | |
'use strict'; | |
let AWS = require('aws-sdk') | |
module.exports = (robot) => { | |
let trans = new AWS.Translate({region: 'us-west-2'}); | |
robot.respond(/PING$/i, (res) => { | |
res.send('PONG'); | |
}); | |
robot.respond(/ADAPTER$/i, (res) => { | |
res.send(robot.adapterName); | |
}); | |
robot.respond(/ECHO (.*)$/i, (res) => { | |
let message = res.match[1]; | |
console.log(message); | |
res.send(message); | |
let params = { | |
SourceLanguageCode: 'ja', | |
TargetLanguageCode: 'en', | |
Text: message | |
}; | |
trans.translateText(params, (err, data) => { | |
if (err) { | |
console.log(err, err.stack); | |
res.send('ごめん、失敗した'); | |
} else { | |
console.log(data); | |
res.send('曰く\n' + data.TranslatedText); | |
} | |
}); | |
}); | |
robot.respond(/TIME$/i, (res) => { | |
res.send(`Server time is: ${new Date()}`); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment