-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommandSelected.js
66 lines (64 loc) · 1.75 KB
/
CommandSelected.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Action Fulfillment of an invitation action.
//
// Input contains:
// - spaceId: SpaceId the command was submitted in.
// - limit: max number of invites to generate cards for (defaults to 10)
//
var openwhisk = require("openwhisk");
var mustache = require("mustache");
var _ = require("lodash");
function main(request) {
return new Promise((resolve,reject) => {
var ow = openwhisk();
if (request.annotationPayload.actionId.startsWith("/invite")) {
ow.actions.invoke({
name: "WatsonWorkspace/GraphQL",
blocking: true,
params: {
string: mustache.render(`{
space(id: "{{spaceId}}") {
members(first: {{limit}}) {
items {
id
email
displayName
}
}
}
}`,request)
}
}).then(resp => {
var spaceMembers =_.remove(resp.response.result.data.space.members.items,"email")
var cards = [];
spaceMembers.forEach(member => {
cards.push({
type: 'INFORMATION',
title: 'Invitation',
subtitle: "Special Event",
text: "Invitation for " + member.displayName,
buttons: [
{
text: "Invite",
payload: {
member: member,
response: {
title: "Invited!",
text: "You've invited " + member.displayName + "."
}
},
style: 'PRIMARY'
}
]
})
})
resolve({
annotation: request,
cards: cards
});
}).catch(err => {
reject(err);
})
}
})
};