Skip to content

Commit

Permalink
[feature] add support for attachments such as from datadog complex
Browse files Browse the repository at this point in the history
messages
  • Loading branch information
after-ephemera committed Jun 27, 2024
1 parent a7590d2 commit b9f5b01
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/listeners/messages/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type App } from "@slack/bolt";
import oncallMentionedCallback from "./oncall-mentioned";
import { type App, KnownEventFromType, subtype } from '@slack/bolt';
import oncallMentionedCallback from './oncall-mentioned';
import {
appMentionedDmHelpCallback,
appMentionedDmLsCallback,
appMentionedDmVersionCallback,
} from "@src/listeners/messages/app-mentioned-dm";
import { oncallMap } from "@api/pd";
} from '@src/listeners/messages/app-mentioned-dm';
import { oncallMap } from '@api/pd';

// These regexes allow for DM messages to the bot without the mention
const VERSION_REGEX = new RegExp(`^version$`);
Expand All @@ -16,10 +16,34 @@ const register = async (app: App): Promise<void> => {
// This regex matches any string that contains a mention of any of the oncall shortnames.
// Updating the config requires a restart of the service.
const allShortnamesRegex = new RegExp(
`.*@(${Object.keys(oncallMap).join("|")})\\b.*`
`.*@(${Object.keys(oncallMap).join('|')})\\b.*`
);
console.log("**** allShortnamesRegex", allShortnamesRegex);
console.log('**** allShortnamesRegex', allShortnamesRegex);
app.message(allShortnamesRegex, oncallMentionedCallback);
app.message(
async ({
context,
message,
next,
}: {
context: any;
message: KnownEventFromType<'message'>;
next: any;
}) => {
// check for edge case where the "attachments" in the message contains the shortname
if (
'attachments' in message &&
allShortnamesRegex.test(JSON.stringify(message.attachments))
) {
const matches = JSON.stringify(message.attachments).match(
allShortnamesRegex
);
context.matches = matches;
await next();
}
},
oncallMentionedCallback
);

app.message(VERSION_REGEX, appMentionedDmVersionCallback);
app.message(LS_REGEX, appMentionedDmLsCallback);
Expand Down

0 comments on commit b9f5b01

Please sign in to comment.