-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
49 lines (41 loc) · 1.27 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import validator from 'validator';
import UuidEncoder from 'uuid-encoder';
const base36Encoder = new UuidEncoder('base36');
'use strict';
function convertId(params) {
const reuqestUUID = params.text.trim();
console.log(reuqestUUID);
let responseText = 'No able to convert the given input `' + reuqestUUID + '`';
if (validator.isUUID(reuqestUUID)) {
const base36UUID = base36Encoder.encode(reuqestUUID);
responseText = 'The namespace name for the UUID `' + reuqestUUID + '` is `' + base36UUID + '`';
}
else if (reuqestUUID.length <= 25) {
const longUUID = base36Encoder.decode(reuqestUUID);
if (validator.isUUID(longUUID)) {
responseText = 'The UUID for the namespace `' + reuqestUUID + '` is `' + longUUID + '`';
} else {
responseText = 'No able to convert the namespace name `' + reuqestUUID + '` to a valid UUID';
}
}
const responseJSON = {
'blocks': [
{
'type': 'section',
'text': {
'type': 'mrkdwn',
'text': responseText,
},
},
{
'type': 'section',
'text': {
'type': 'mrkdwn',
'text': '_powered by IBM Cloud Functions_ :cloudfunctions-whitecircle:',
},
},
],
};
return responseJSON;
}
global.main = convertId;