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: 1
- Abstract Bridge Layer: Refactor
Assistant
I'll start by exploring the codebase to understand the current structure, then plan and implement the messaging channels expansion.
Assistant
Let me read the key files I need to understand before planning.
Assistant
Now I have a thorough understanding of the codebase. Let me create the operational plan and begin implementation.
Operational Plan
- 1. Create abstract bridge interface (
src/bridge/interface.ts) - 2. Create channel-agnostic message composer (
src/agent/channel-format.ts) - 3. Refactor handler to support multiple channels (generalize sender registration)
- 4. Create Slack bridge (
src/bridge/slack/) - 5. Create Telegram bridge (
src/bridge/telegram/) - 6. Create Discord bridge (
src/bridge/discord/) - 7. Add environment variables for new channels to config/env.ts
- 8. Update
src/index.tsstartup logic for multi-bridge support - 9. Create messaging configuration (
config/messaging.json) - 10. Write unit tests
- 1. Create abstract bridge interface (
Assistant
Let me start by creating the abstract bridge interface and the channel formatters in parallel.
Assistant
I need to fix the
requirein channel-format.ts - this is ESM only.Assistant
Now let me refactor the handler to support multiple channels. The key change is generalizing
registerWhatsAppSenderto support channel-aware senders, and adding aregisterChannelSender/registerMessageSenderalongside the existing one for backward compatibility.Assistant
Now let me update the handler to support multi-channel message sending. I'll add a
registerChannelSenderalongside the existingregisterWhatsAppSenderfor backward compat.Assistant
Now let me create all three bridge implementations in parallel.
Assistant
Now let me add the environment variables and update the startup logic. I'll also read the .env.example to update it.
Assistant
Now let me add the env vars and update the startup logic in parallel.
Assistant
Now let me create the bridge manager that coordinates multiple bridges, and update the index.ts startup.
Assistant
Now update
index.tsto initialize additional bridges after the WhatsApp bridge starts.Assistant
Now add channel bridge initialization after the WhatsApp bridge starts, and destroy them on shutdown.
Assistant
Fix the comment numbering in the shutdown sequence:
Assistant
Now let me write unit tests. First let me check the existing test patterns.
Assistant
Now let me verify compilation.
Assistant
I need to fix the unused imports and handle the missing module declarations. The SDKs are optional runtime dependencies — I'll add type stubs.
Assistant
Now for the missing module declarations, I'll create type declaration stubs for the optional dependencies.
Assistant
Compilation passes cleanly. Now let me run the tests.
Assistant
All 21 tests pass and compilation is clean. Let me also run the existing tests to make sure nothing is broken.
Assistant
The handler.test.ts failure is pre-existing (missing
mock-session-manager.jshelper, unrelated to my changes). All tests I touched pass, and the core tests (composer, whatsapp-format, index-runtime) pass too.Assistant