Retrieves the ID from the Slack user profile. The user profile is identified using the Questetra account email address as the key. You can post a message with mentions using your ID.
Configs
C1: OAuth2 Setting *
C2: Select QUSER Data for Questetra Account User *
C3: Select STRING DATA for Slack ID *
Script (click to open)
main();
function main() {
const oauth2 = configs.get("conf_OAuth2");
let text = "";
if (configs.get("Text") !== "" && configs.get("Text") !== null){
text = configs.get("Text");
}
const quserNum = configs.get("conf_Quser");
const email = engine.findDataByNumber( quserNum ).getEmail();
const slackIdNum = configs.get("conf_SlackId");
engine.log("email: " + email);
const id = usersLookupByEmail(oauth2, email);
engine.setDataByNumber( slackIdNum, id );
}
/**
* users.lookupByEmail https://api.slack.com/methods/users.lookupByEmail
* @param {String} oauth2
* @param {String} email
*/
function usersLookupByEmail(oauth2, email) {
let getUri = "https://slack.com/api/users.lookupByEmail";
let request = httpClient.begin()
if (oauth2 !== "" && oauth2 !== null){
request = request.authSetting(oauth2);
}
request = request.queryParam( "email", email );
const response = request.get( getUri );
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
let responseJson;
try {
responseJson = JSON.parse(responseTxt);
} catch(e) {
engine.log("failed to parse as json");
engine.log(`status: ${status}`);
engine.log(responseTxt);
throw `Failed to users lookup By email. status: ${status}`;
}
if (responseJson.ok !== true ) {
const error = `Failed to send`;
engine.log(`status: ${status}`);
engine.log(responseTxt);
throw error;
}
engine.log('Slack Id:' + responseJson.user.id);
return responseJson.user.id;
}
2022-03-14 (C) Questetra, Inc. (MIT License) https://support.questetra.com/bpmn-icons/slack-get-id/ The Add-on import feature is available with Professional edition. Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
Notes
Gets an ID from the user profile on Slack, the business communication tool
You can use the retrieved ID when posting a mentioned message to Slack
Example of specifying a mention: “<@XXXXXXXX>” (“XXXXXXXX” should be the ID)
You need to create a “Slack app” in advance
For creating a new app click Create New App in [Settings & administration] > [Manage apps] > [Build]