forked from chaoss/chaoss-slack-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
154 lines (126 loc) · 4.53 KB
/
app.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
146
147
148
149
150
151
152
153
154
const { App } = require('@slack/bolt');
const newbie = require('./components/newbie');
const theActions = require('./components/actions/actionResponses');
const mentorshipAction = require('./components/actions/mentorshipAction');
const mentorshipResponses = require('./components/actions/mentorshipResponses');
const memberJoinChannel = require('./components/joinChannel');
const outreachyPrompt = require('./components/outreachyPrompt');
const joinTeam = require('./components/joinTeam');
const dotenv = require('dotenv');
dotenv.config();
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3000,
});
// ********************************NEWBIES*********/
//This responds to a member when they type newbie in any channel where the bot is present
app.message(/newbie/i, async ({ message, client, logger }) => {
newbie.newHere(message, client, logger);
});
// handle the button click and show the responses
app.action('develop', async ({ ack, say }) => {
await ack();
theActions.develop(say);
});
app.action('joinMeet', async ({ ack, say }) => {
// Acknowledge the action
await ack();
theActions.joinMeet(say);
});
app.action('contribute', async ({ ack, say }) => {
// Acknowledge the action
await ack();
theActions.contribute(say);
});
app.action('helpWithWebsite', async ({ ack, say }) => {
await ack();
theActions.helpWithWebsite(say);
});
app.action('docs', async ({ ack, say }) => {
await ack();
theActions.docs(say);
});
app.action('mentorship', async ({ ack, say }) => {
await ack();
mentorshipAction.mentorship(say);
});
// this handler is for the nested radio buttons above
app.action('mentorship_selection', async ({ action, ack, say }) => {
await ack();
console.log(action.selected_option.value);
if (action.selected_option.value === 'outreachy') {
mentorshipResponses.outreachy(say);
}
if (action.selected_option.value === 'gsoc') {
mentorshipResponses.gsoc(say);
}
if (action.selected_option.value === 'gsod') {
mentorshipResponses.gsod(say);
}
});
app.action('implement_metrics', async ({ ack, say }) => {
await ack();
theActions.implement_metrics(say);
});
app.action('learn_something_else', async ({ ack, say }) => {
await ack();
theActions.learn_something_else(say);
});
// *****************PROJECTBOT CHANNEL FOR TESTING****************************/
app.event('member_joined_channel', async ({ event, client, logger }) => {
memberJoinChannel.memberJoin(event, client, logger);
});
//****************************************** */
// When a user joins the team, the bot sends a DM to the newcommer asking them how they would like to contribute
app.event('team_join', async ({ event, client, logger }) => {
joinTeam.joinTeamSlack(event, client, logger);
});
//*************************************************************** */
// *************Send message about outreachy**********/
app.message(/outreachy/i, async ({ message, say, logger }) => {
outreachyPrompt.outreachyMessage(message, say, logger);
});
//******************************************************* */
// app.message(/hello|hey|hi/i, async ({ message, say }) => {
// await say(`Hello there <@${message.user}>!`);
// });
// *************************************** DIRECT MESSAGE - ONE TIME ANNOUNCEMENT TO INTRODUCE THE BOT************/
/*
let usersStore = {};
app.message('intro-CHAOSS', async ({ client, logger }) => {
// Call the users.list method using the WebClient
const result = await client.users.list();
saveUsers(result.members);
try {
for (let i = 0; i < userId.length; i++) {
await client.chat.postMessage({
channel: userId[i],
text: `Hello, I'm CHAOSS BOT! I am a simple bot. I am here to welcome newcomers. If you need more information about CHAOSS, you can type in 'newbie' in the <#C0207C3RETX> channel and I will show you around.`,
});
}
} catch (error) {
logger.error(error);
}
});
// Put users into the JavaScript object
let userId = [];
function saveUsers(usersArray) {
usersArray.forEach(function (user) {
// Key user info on their unique user ID
userId.push(user['id']);
// Store the entire user object (you may not need all of the info)
usersStore[userId] = user;
// console.log(userId);
});
}
*/
//************ */
(async () => {
// Start your app
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running!');
})();