-
Notifications
You must be signed in to change notification settings - Fork 40
/
app.js
167 lines (139 loc) · 5.21 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
155
156
157
158
159
160
161
162
163
164
165
166
167
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 outreachyPrompt = require("./components/outreachyPrompt");
const {
chaossAfricaInfo,
joinChaossAfrica,
} = require("./components/chaossAfrica");
const joinTeam = require("./components/joinTeam");
const memberJoinChannel = require("./components/joinChannel");
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);
});
//This responds to a member when they type africa in any channel where the bot is present
app.message(/africa-info/i, async ({ message, client, logger }) => {
chaossAfricaInfo(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.googleSummerOfCode(say);
}
if (action.selected_option.value === "gsod") {
mentorshipResponses.googleSeasonOfDocs(say);
}
});
app.action("implement_metrics", async ({ ack, say }) => {
await ack();
theActions.implement_metrics(say);
});
app.action("regional_chapters", async ({ ack, say }) => {
await ack();
theActions.regional_chapters(say);
});
app.action("learn_something_else", async ({ ack, say }) => {
await ack();
theActions.learn_something_else(say);
});
app.action("faqs", async ({ ack, say }) => {
await ack();
theActions.faqs(say);
});
//****************************************** */
// 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); // this is the function that sends the DM
memberJoinChannel.memberJoin(event, client, logger); // this is for the #projectbot channel
});
//*********************************************************** */
// *******When a user join chaossafrica channel, the bot sends a welcome message and the goal of the community******//
app.event("member_joined_channel", async ({ event, client, logger }) => {
joinChaossAfrica.joinChaossAfrica(event, client, logger);
});
// ************************************************************************************************//
// *************Send message about outreachy**********/
app.message(/outreachy/i, async ({ message, say, logger }) => {
outreachyPrompt.outreachyMessage(message, say, logger);
});
// *******************************DIRECT MESSAGE - ONE TIME ANNOUNCEMENT************/
/*
let usersStore = {};
app.message('survey-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 there! We recently launched a community survey to get your feedback on how to make our community more welcoming and inclusive. If you have considered yourself part of the community, we would love you to share your thoughts and experiences by completing this survey: https://chaossproject.limesurvey.net/835156?lang=en
Thank you`,
});
}
} 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 () => {
await app.start(process.env.PORT || 3000);
console.log("⚡️ Bolt app is running!");
})();