Skip to content

Commit

Permalink
#20 - testing commands with Gator; need some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaida committed May 4, 2020
1 parent 80f37e4 commit 92b6aaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app-mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const msgText = require('./bot-response/message-text');
------------------*/
const app_mentions = (app, store) => {
app.event('app_mention', async({ event, context }) => {
console.log(event, context);
console.log('Event:', event);
// Gather applicable info
const text = event.text; // raw text from the mention
const sentByUserID = event.user; // ID of user who sent the message
Expand Down Expand Up @@ -245,7 +245,7 @@ const app_mentions = (app, store) => {
);
if (!!handoffMsg) {
// Send DM to newly assigned user notifying them of the handoff message
const oncallUserDMChannel = utils.userDMchannel(usermention);
const oncallUserDMChannel = utils.getUserID(usermention);
const link = `https://${process.env.SLACK_TEAM}.slack.com/archives/${channelID}/p${event.ts.replace('.', '')}`;
// Send DM to on-call user notifying them of the message that needs their attention
const sendDM = await app.client.chat.postMessage(
Expand Down Expand Up @@ -315,7 +315,7 @@ const app_mentions = (app, store) => {
if (!!handoffMsg) {
// There is a handoff message
// Send DM to newly assigned user notifying them of handoff message
const oncallUserDMChannel = utils.userDMchannel(usermention);
const oncallUserDMChannel = utils.getUserID(usermention);
const link = `https://${process.env.SLACK_TEAM}.slack.com/archives/${channelID}/p${event.ts.replace('.', '')}`;
// Send DM to on-call user notifying them of the message that needs their attention
const sendDM = await app.client.chat.postMessage(
Expand Down Expand Up @@ -491,7 +491,7 @@ const app_mentions = (app, store) => {
if (!!oncallUser) {
// If someone is assigned to concierge...
const link = `https://${process.env.SLACK_TEAM}.slack.com/archives/${channelID}/p${event.ts.replace('.', '')}`;
const oncallUserDMChannel = utils.userDMchannel(usermention);
const oncallUserDMChannel = utils.getUserID(oncallUser);
// Send DM to on-call user notifying them of the message that needs their attention
const sendDM = await app.client.chat.postMessage(
utils.msgConfig(botToken, oncallUserDMChannel, msgText.dmToAssigned(rotation, sentByUserID, channelID, link))
Expand Down
22 changes: 8 additions & 14 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ const utils = {
@Returns: string
----*/
cleanText(msg) {
if (msg.startsWith('Reminder: ')) {
return msg.replace('Reminder: ', '').trim();
} else {
return msg.trim();
}
return msg.replace('Reminder: ', '').replace("_(sent with '/gator')_", '').trim();
},
/*----
Get user ID from mention
Expand Down Expand Up @@ -116,7 +112,13 @@ const utils = {
const noEmpty = arr.filter(item => !!item !== false); // Remove falsey values
const noDupes = new Set(noEmpty); // Remove duplicates
const cleanArr = [...noDupes]; // Convert set back to array
return cleanArr || [];
// Clean any |user.name out of user staff (this happens when a bot issues the command)
const userCleanArr = [];
cleanArr.forEach(user => {
const cleanUser = user.includes('|') ? `${user.split('|')[0]}>` : user;
userCleanArr.push(cleanUser);
});
return userCleanArr || [];
};
return {
rotation: res[2],
Expand Down Expand Up @@ -172,14 +174,6 @@ const utils = {
@Params: botToken, channelID, text
@Returns: object
----*/
userDMchannel(usermention) {
return usermention.replace('<@', '').replace('>', '').split('|')[0];
},
/*----
Config object for Slack messages
@Params: botToken, channelID, text
@Returns: object
----*/
msgConfig(botToken, channelID, text) {
return {
token: botToken,
Expand Down

0 comments on commit 92b6aaa

Please sign in to comment.