Skip to content

Instantly share code, notes, and snippets.

@operando
Last active May 29, 2021 07:20
Show Gist options
  • Save operando/8909c0095fb06fe81c206caa8584735d to your computer and use it in GitHub Desktop.
Save operando/8909c0095fb06fe81c206caa8584735d to your computer and use it in GitHub Desktop.
Googleスプレッドシートで "=slack_id(email)" でメールアドレスからSlack IDを調べる独自関数をGoogle App Scriptで作る
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