This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
teams_features.js
145 lines (130 loc) · 4.44 KB
/
teams_features.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { TeamsInvokeMiddleware } = require('botkit');
module.exports = function(controller) {
if (!controller.adapter.name) {
controller.adapter.use(new TeamsInvokeMiddleware());
const adaptiveCard = {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Here is a ninja cat:"
},
{
"type": "Image",
"url": "http://adaptivecards.io/content/cats/1.png",
"size": "Medium"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Message Submit",
"id": "begin",
"data": {
"command": "message"
}
},
{
"type": "Action.Submit",
"title": "Card Submit",
"id": "begin",
"data": {
"command": "card"
}
},
{
"type": "Action.Submit",
"title": "Close",
"id": "begin",
"data": {
"command": "close"
}
},
],
"horizontalAlignment": "Center"
}
],
"version": "1.0"
}
controller.hears('getTeamDetails', 'message', async(bot, message) => {
try {
await bot.reply(message, JSON.stringify(await bot.teams.getTeamDetails(bot.getConfig('context'))));
} catch(err) {
await bot.reply(message, err.message);
}
});
controller.hears('getTeamChannels', 'message', async(bot, message) => {
try {
await bot.reply(message, JSON.stringify(await bot.teams.getTeamChannels(bot.getConfig('context'))));
} catch(err) {
await bot.reply(message, err.message);
}
});
controller.hears('getMember', 'message', async(bot, message) => {
try {
await bot.reply(message, JSON.stringify(await bot.teams.getMember(bot.getConfig('context'), message.user)));
} catch(err) {
await bot.reply(message, err.message);
}
});
controller.hears('taskModule', 'message', async(bot, message) => {
await bot.reply(message,{
attachments: [{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"buttons": [
{
"type": "invoke",
"title": "Task Module",
"value": {type: 'task/fetch'}
}
],
"text": "Launch a task module by clicking the button.",
"title": "INVOKE A TASK MODULE!"
}
}]
});
});
controller.on('task/fetch', async(bot, message) => {
await bot.replyWithTaskInfo(message,{
"type": "continue",
"value": {
"title": "Task module title",
"height": 500,
"width": "medium",
card: {
contentType: 'application/vnd.microsoft.card.adaptive',
content: adaptiveCard,
}
}
})
});
controller.on('task/submit', async(bot, message) => {
if (message.value.data.command == 'message') {
// reply with a message
await bot.replyWithTaskInfo(message, {
type: 'message',
value: 'Submitted!',
});
} else if (message.value.data.command == 'card') {
// reply with another card
await bot.replyWithTaskInfo(message, {
"type": "continue",
"value": {
"title": "Task module title",
"height": 500,
"width": "medium",
card: {
contentType: 'application/vnd.microsoft.card.adaptive',
content: adaptiveCard,
}
}
});
} else {
// just close the task module
await bot.replyWithTaskInfo(message, null);
}
});
}
}