Skip to content

Commit

Permalink
fix: mentions causing bot to mis-identity user, markdown codes not wo…
Browse files Browse the repository at this point in the history
…rking correctly
  • Loading branch information
Yengas committed Dec 29, 2022
1 parent 789dfda commit 4aa9872
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/application/slack-adapter/slack-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { SlackMessageEventWithEnvelope } from "../../domain/slack-adapter/slack-
import { SlackConversationDynamodbRepository } from "../../infrastructure/dynamodb/slack-conversation-dynamodb.repository";

export class SlackEventHandler {
private static readonly STRIP_INITIAL_MENTION_REGEX = /^(\s*<@[^>]+>\s*)/;

private static tryGetMessageStartingMention(
envelope: SlackMessageEventWithEnvelope
): { userId: string } | undefined {
Expand Down Expand Up @@ -35,6 +37,10 @@ export class SlackEventHandler {
return authorization?.is_bot ? authorization?.user_id : undefined;
}

private static stripInitialMention(text: string): string {
return text.replace(this.STRIP_INITIAL_MENTION_REGEX, "");
}

constructor(
private readonly repository = new SlackConversationDynamodbRepository(),
private readonly commandBus: CommandBus = globalCommandBus
Expand Down Expand Up @@ -91,7 +97,7 @@ export class SlackEventHandler {
message: {
id: event.ts,
author: { userId: event.user },
text: event.text,
text: SlackEventHandler.stripInitialMention(event.text),
},
});
}
Expand All @@ -107,7 +113,7 @@ export class SlackEventHandler {
initialMessage: {
id: event.ts,
author: { userId: event.user },
text: event.text,
text: SlackEventHandler.stripInitialMention(event.text),
},
metadata: {
threadId: ts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const slackSoftwareEngPersona: Persona = {
name: "slack-software-eng",
basePrompt: `Instructions for ${config.bot.name}:
You're a regular Slack user.
When you want to provide code examples, you wrap them around triple backticks.
When providing code examples, use triple backticks and do not suffix the markdown shortcut for the language.
You always like providing lengthy responses and explaining things.
You are helpful and descriptive.
You make well-informed decisions and cite your sources if you can.
Expand Down

0 comments on commit 4aa9872

Please sign in to comment.