-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove slack new chat message (#38)
Co-authored-by: Maciej Jastrzebski <[email protected]>
- Loading branch information
1 parent
1b5d925
commit 251f05a
Showing
6 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'slack-example': patch | ||
'@callstack/byorg-slack': patch | ||
--- | ||
|
||
Added useful plugins for normalizing threads (Slack started adding "New chat" message). Updated example slack app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createApp, createMockChatModel, Message } from '@callstack/byorg-core'; | ||
import { describe, expect, it, vitest } from 'vitest'; | ||
import { slackThreadNormalizerPlugin } from '../plugins/thread-normalization.js'; | ||
|
||
describe('threadNormalizer', () => { | ||
it('should remove slack "New chat" initial message', async () => { | ||
const messages: Message[] = [ | ||
{ role: 'user', content: 'New chat\n' }, | ||
{ role: 'user', content: 'Hello!' }, | ||
]; | ||
const baseModel = createMockChatModel({ delay: 0, seed: 3 }); | ||
|
||
const modelSpy = vitest.spyOn(baseModel, 'generateResponse'); | ||
|
||
const app = createApp({ | ||
chatModel: baseModel, | ||
plugins: [slackThreadNormalizerPlugin], | ||
}); | ||
|
||
await app.processMessages(messages); | ||
|
||
expect(modelSpy.mock.calls[0][0]['messages']).toEqual([{ role: 'user', content: 'Hello!' }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ApplicationPlugin, MessageResponse } from '@callstack/byorg-core'; | ||
import { logger } from '@callstack/byorg-utils'; | ||
|
||
/** | ||
* Slack plugin for normalizing messages coming from Slack [AI apps](https://api.slack.com/docs/apps/ai). | ||
*/ | ||
export const slackThreadNormalizerPlugin: ApplicationPlugin = { | ||
name: 'slack-thread-normalizer', | ||
middleware: async (context, next): Promise<MessageResponse> => { | ||
const { messages } = context; | ||
|
||
if (messages[0].content === 'New chat\n' && messages[1]?.role === 'user') { | ||
context.messages = messages.slice(1); | ||
logger.debug('Removed Slack "New Chat" message'); | ||
} | ||
|
||
// Continue middleware chain | ||
return await next(); | ||
}, | ||
}; |