Last active
November 30, 2019 16:12
-
-
Save orimajp/b03c03c6cfdb1ef32accad5bd6259bb8 to your computer and use it in GitHub Desktop.
日本語変換GAS/Slack連携スクリプト
This file contains hidden or 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
var token = '*********************'; // トークン | |
function doPost(e) { | |
var verificationToken = e.parameter.token; | |
if (verificationToken !== token) { | |
throw new Error('Invalid token'); | |
} | |
var translationText = e.parameter.text; | |
if (translationText === '') { | |
var errorMessage = { | |
text: '翻訳する文章を入力してください。' | |
}; | |
return ContentService.createTextOutput(JSON.stringify(errorMessage)).setMimeType(ContentService.MimeType.JSON); | |
} | |
var translatedText = LanguageApp.translate(translationText, 'en', 'ja'); | |
var translateResultMessage = { | |
attachments: [ | |
{ | |
pretext: '原文:', | |
text: translationText | |
}, | |
{ | |
pretext: '翻訳:', | |
text: translatedText | |
} | |
] | |
}; | |
return ContentService.createTextOutput(JSON.stringify(translateResultMessage)).setMimeType(ContentService.MimeType.JSON); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment