Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Worked on slackbot and updated MLH links (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika authored and shashankmurching committed Sep 8, 2019
1 parent 2cf1a4a commit 3abf4db
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 47 deletions.
24 changes: 24 additions & 0 deletions app/pages/apply.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ class Apply extends React.Component {
theme={this.props.theme}
onSubmit={this.onSubmit}
/>
<p>
By applying, you confirm you have read and agree to
the{' '}
<a href="https://static.mlh.io/docs/mlh-code-of-conduct.pdf">
MLH Code of Conduct
</a>
, the{' '}
<a href="https://mlh.io/privacy">
MLH Privacy Policy
</a>
, the{' '}
<a href="https://github.com/MLH/mlh-policies/blob/master/prize-terms-and-conditions/contest-terms.md">
MLH Contest Terms and Conditions
</a>
, the{' '}
<a href="https://docs.google.com/document/d/1L9wC7lfXmOBCKdUQancuoYQf86KIQqUJ0is4dr8QqQM/pub">
MHacks Code of Conduct
</a>
, and the{' '}
<a href="https://docs.google.com/document/d/1tFmaC_eVVPJ9fKnjGeYHRX2_th3-JOd9ZP-IoTEM91I/pub">
MHacks Liability Waiver
</a>
.
</p>
</div>
</FormContainer>
<NotificationStack
Expand Down
5 changes: 5 additions & 0 deletions app/pages/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ class HeaderLinks extends React.Component {
Edit Profile
</StyledNavLink>
) : null}
{isLoggedIn && isAccepted ? (
<StyledNavLink to={routes.CONFIRM} color={color}>
Confirm
</StyledNavLink>
) : null}
{isLoggedIn ? (
<StyledNavLink to={routes.DASHBOARD} color={color}>
Dashboard
Expand Down
1 change: 1 addition & 0 deletions deploy/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ services:
- NEWRELIC_ENABLED
- NEWRELIC_APP_NAME
- NEWRELIC_LICENSE_KEY
- SLACKBOT_TOKEN
links:
- mhacks_db
19 changes: 19 additions & 0 deletions server/db/model/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,25 @@ var schema = new mongoose.Schema(
auth_groups: ['admin', 'reader']
}
]
},
mlh_coc_agreement: {
type: Boolean,
required: true,
form: {
user_editable: true,
label: 'I have read and agree to the MLH Code of Conduct.',
required_value: true
}
},
mlh_affiliation_agreement: {
type: Boolean,
required: true,
form: {
user_editable: true,
label:
'I authorize you to share my application/registration information for event administration, ranking, MLH administration, pre- and post-event informational e-mails, and occasional messages about hackathons in-line with the MLH Privacy Policy. I further agree to the terms of both the MLH Contest Terms and Conditions and the MLH Privacy Policy.',
required_value: true
}
}
},
defaultEndSchema
Expand Down
19 changes: 0 additions & 19 deletions server/db/model/Confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,6 @@ var schema = new mongoose.Schema(
auth_groups: ['admin', 'reader', 'sponsor']
}
]
},
mlh_coc_agreement: {
type: Boolean,
required: true,
form: {
user_editable: true,
label: 'I have read and agree to the MLH Code of Conduct.',
required_value: true
}
},
mlh_affiliation_agreement: {
type: Boolean,
required: true,
form: {
user_editable: true,
label:
'I authorize you to share my application/registration information for event administration, ranking, MLH administration, pre- and post-event informational e-mails, and occasional messages about hackathons in-line with the MLH Privacy Policy. I further agree to the terms of both the MLH Contest Terms and Conditions and the MLH Privacy Policy.',
required_value: true
}
}
},
defaultEndSchema
Expand Down
25 changes: 21 additions & 4 deletions server/interactors/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function sendMessage(location, message) {
channel: message.channel,
text: message.text,
blocks: message.blocks
}
},
json: true
});
}
}
Expand All @@ -30,7 +31,8 @@ function createGroupDM(token, users) {
form: {
token: token,
users: users.join()
}
},
json: true
});
}

Expand All @@ -41,7 +43,20 @@ function getBotUserID(token, bot) {
form: {
token: token,
bot: bot
}
},
json: true
});
}

function getUserForID(token, user_id) {
return request({
method: 'POST',
uri: 'https://slack.com/api/users.info',
form: {
token: token,
user: user_id
},
json: true
});
}

Expand All @@ -54,13 +69,15 @@ function postSnippet(token, message) {
channels: message.channels,
content: message.content,
title: message.title
}
},
json: true
});
}

module.exports = {
sendMessage,
createGroupDM,
getBotUserID,
getUserForID,
postSnippet
};
55 changes: 31 additions & 24 deletions server/routes/api/mentorshipbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ var router = require('express').Router(),
config = require('../../../config/default.js'),
slack = require('../../interactors/slack.js');

const createBlockWithButton = (user_name, text) => {
const createBlockWithButton = (user_id, user_name, text) => {
return JSON.stringify([
{
type: 'section',
text: {
type: 'mrkdwn',
text: formatInquiry(user_name, text)
text: formatInquiry(user_id, text)
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: `Help User ${user_name}`,
text: `Help User @${user_name}`,
emoji: true
},
value: 'pair_user_with_mentor'
Expand All @@ -23,30 +23,43 @@ const createBlockWithButton = (user_name, text) => {
]);
};

const formatInquiry = (user_name, text) =>
`*${user_name} wants help with:* ${text}`;
const formatInquiry = (user_id, text) =>
`*<@${user_id}> wants help with:* ${text}`;
const strikeThroughInquiry = text => `~${text}~`;

router.post('/', function(req, res) {
let inquiry = req.body || '';
if (inquiry.text && inquiry.command == '/helpmewith') {
slack
.sendMessage(config.slackbot_token, {
channel: config.slack_mentorship_channel,
text: inquiry.user_id, // NOTE: using text object is currently the best way to pass this id, but Slack is phasing out usernames. Check API in future.
blocks: createBlockWithButton(inquiry.user_name, inquiry.text) // defines message content and appearance
})
.getUserForID(config.slackbot_token, inquiry.user_id)
.then(response => {
response = JSON.parse(response);
if (!response.ok) throw Error(response.error);
res.send({
response_type: 'in_channel',
text: `Your inquiry: '${inquiry.text}' was sent to the ${config.slack_mentorship_channel} channel`
});
slack
.sendMessage(config.slackbot_token, {
channel: config.slack_mentorship_channel,
text: inquiry.user_id, // NOTE: using text object is currently the best way to pass this id, but Slack is phasing out usernames. Check API in future.
blocks: createBlockWithButton(
inquiry.user_id,
response.user.real_name,
inquiry.text
) // defines message content and appearance
})
.then(() => {
res.send({
response_type: 'in_channel',
text: `Your inquiry: '${inquiry.text}' was sent to the ${config.slack_mentorship_channel} channel`
});
})
.catch(e => {
console.error(e);
res.status(500).json(e);
});
})
.catch(e => {
console.error(e);
res.status(500).json(e);
});
} else {
res.status(400).send({ status: false });
}
});

Expand All @@ -69,19 +82,13 @@ router.post('/interactions/', function(req, res) {
slack
.createGroupDM(config.slackbot_token, users)
.then(response => {
response = JSON.parse(response);
if (!response.ok) throw Error(response.error);

// Post question in GroupDM.
slack
.sendMessage(config.slackbot_token, {
channel: response.channel.id,
text: `${payload.user.username},\n${inquiry}\nThank you for helping!`
text: `<@${payload.user.id}>,\n\n${inquiry}\n\nThank you for helping!`
})
.then(response => {
response = JSON.parse(response);
if (!response.ok) throw Error(response.error);

.then(() => {
// Cross-out inquiry in mentorship channel
slack
.sendMessage(payload.response_url, {
Expand Down

0 comments on commit 3abf4db

Please sign in to comment.