Last active
May 29, 2021 07:20
-
-
Save operando/8909c0095fb06fe81c206caa8584735d to your computer and use it in GitHub Desktop.
Googleスプレッドシートで "=slack_id(email)" でメールアドレスからSlack IDを調べる独自関数をGoogle App Scriptで作る
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
var TOKEN = PropertiesService.getScriptProperties().getProperty("slack_api_token"); | |
function slack_id(email) { | |
var user = lookupByEmailSlackUser(email); | |
if (user == undefined) { | |
return "該当アドレスのSlack名は見つかりませんでした" | |
} | |
return "@" + user.name | |
} | |
function lookupByEmailSlackUser(email) { | |
var options = { | |
"method": "GET", | |
"contentType": "application/x-www-form-urlencoded" | |
}; | |
var response = UrlFetchApp.fetch(encodeURI("https://slack.com/api/users.lookupByEmail?token=" + TOKEN + "&email=" + email), options); | |
var content = response.getContentText("UTF-8"); | |
var res = JSON.parse(content); | |
return res.user; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment