You are an autonomous coding agent working on issue FETCH-4. Task 📨 Expanded Messaging…
- User
You are an autonomous coding agent working on issue FETCH-4.
Task
📨 Expanded Messaging Channels (Slack, Telegram, Discord)
Description
Expand Fetch's communication capabilities beyond WhatsApp to support professional chat platforms. This allows teams to use Fetch in their existing workflows.
Plan
- Abstract Bridge Layer: Refactor
src/bridge/to support multiple providers (currently tightly coupled towhatsapp-web.js). - Slack Integration:
- Use
@slack/boltSDK. - Support threads, mentions, and file uploads.
- Use
- Telegram Integration:
- Use
telegrafor similar. - Support voice notes and groups.
- Use
- Discord Integration:
- Use
discord.js. - Support channel-based context and role-based access.
- Use
configuration
Create
config/messaging.jsonor maintain via.env:SLACK_BOT_TOKEN,SLACK_APP_TOKENTELEGRAM_BOT_TOKENDISCORD_TOKEN
Associated Files
src/bridge/interface.ts(New abstract interface)src/bridge/slack/src/bridge/telegram/src/bridge/discord/src/index.ts(Update startup logic)
Instructions
-
Write an Operational Plan using markdown checkboxes (
- [ ]pending,- [x]done). -
Work through each step. After completing a step, restate the plan with updated checkboxes.
-
Use all available tools to implement changes.
-
Verify your work compiles/passes. Do NOT stop until all items are checked off.
Attempt: 25
- Abstract Bridge Layer: Refactor
Assistant
I'll start by exploring the codebase to understand the current structure before planning.
Assistant
Now let me read the key files I'll need to modify.
Assistant
Let me check the existing tests and .env.example.
Assistant
Let me check how formatting works to understand what needs to be abstracted.
Assistant
Now I have a complete understanding. Let me write the operational plan and start implementing.
Assistant
Now let me set up the operational plan and start working.
Operational Plan — FETCH-4: Expanded Messaging Channels
- Step 1: Create abstract
MessagingBridgeinterface (src/bridge/interface.ts) - Step 2: Create message formatting abstraction (
src/bridge/format.ts) — platform-agnostic formatting - Step 3: Refactor WhatsApp bridge to implement the abstract interface
- Step 4: Implement Slack integration (
src/bridge/slack/) - Step 5: Implement Telegram integration (
src/bridge/telegram/) - Step 6: Implement Discord integration (
src/bridge/discord/) - Step 7: Add env config for new platforms (
config/env.ts,.env.example) - : Update startup logic in to support multi-bridge
- Step 1: Create abstract
Assistant
Step 1: Create the abstract
MessagingBridgeinterfaceAssistant
Step 2: Create platform-agnostic formatting layer
Assistant
Step 3: Refactor WhatsApp bridge to implement the abstract interface
The WhatsApp bridge is large and complex. I'll add the
MessagingBridgeimplementation by makingBridgeimplement the interface, adding the required event emitter pattern, while preserving all existing behavior.Assistant
Now I'll add the
MessagingBridgeinterface implementation to the existingBridgeclass. The key insight is that the WhatsApp bridge is deeply coupled with security gates, handler, and task progress — I need to add the interface conformance without breaking any of the existing behavior.Assistant
Now update the Bridge class to implement the MessagingBridge interface:
Assistant
Now I need to fix all references to
this.isReadyto usethis._isReady:Assistant
Now add the
MessagingBridgeinterface methods. I'll add them before thedestroy()method:Assistant
Now emit bridge events from the existing WhatsApp event handlers. Let me update the
ready,authenticated,disconnected, andauth_failurehandlers to also emit through the bridge interface:Assistant
Also add QR code event emission:
Assistant
Good. The WhatsApp bridge now implements
MessagingBridge. Let me mark this as complete and move on.Assistant
Step 4: Implement Slack integration
Assistant
Step 5: Implement Telegram integration
Assistant
Step 6: Implement Discord integration
Assistant
Step 7: Add env config for new platforms
Assistant
Now update
.env.example:Assistant
Step 8: Update startup logic for multi-bridge
I need to create a bridge orchestrator that manages multiple bridges and update
index.tsto start enabled bridges.Assistant
Now update
src/index.tsto start additional bridges:Assistant
Now add the additional bridge startup after WhatsApp bridge starts, and cleanup in shutdown:
Assistant
Add cleanup for additional bridges in the shutdown and logout paths:
Assistant
Now update the shutdown function to also stop additional bridges:
Assistant
Fix the comment numbering in shutdown (3→4, 4→5):
Assistant
Step 9: Install npm dependencies
Assistant
Step 10: Add unit tests
Let me check an existing test for patterns.
Assistant
Now let me write the tests.
Assistant
Now let me run the tests and check compilation.
Assistant
Step 11: Verify compilation
Assistant
Let me fix the compilation errors. The pm.js errors are pre-existing. Let me fix my new code.
Assistant
Now fix the Slack import —
GenericMessageEventis not a named export. Let me check the @slack/bolt types.Assistant
It doesn't exist. Let me fix the Slack bridge to use inline typing instead.
Assistant
Now fix the unused
sayparameter:Assistant
Compilation passes (the only remaining errors are pre-existing
pm.jsmodule issues, not from our changes).Now let's run the new tests.
Assistant
All 20 tests pass. Let's also make sure existing tests still pass.
Assistant
Let me check if these failures are pre-existing or caused by our changes.
Assistant
All failures are from the pre-existing
pm.jsmodule issue (which also cascades through handler, agent-core, command-parser etc. tests). None of our new code is in the failure list. The 2 new test files (bridge-interface, bridge-format) both pass.Let me verify explicitly that our new tests are in the passing set:
Assistant
All 3 bridge test files pass (including the pre-existing
bridge-progress-message.test.ts).Assistant