Plexus Communications
A comprehensive multi-platform communications integration library for Plexus RPC, providing unified APIs for email, Discord, SMS, push notifications, Telegram, WhatsApp, and Slack.
Features
- Multi-Account Architecture - Register and manage multiple accounts per platform at runtime
- Streaming APIs - Event-driven architecture with real-time message streaming
- SQLite Storage - Persistent account configuration storage
- Modular Design - Each platform is an independent activation
- Real-time Events - Discord Gateway support for live message streams
Supported Platforms
✅ Email (v2.0.0)
- SMTP Sending - Support for standard SMTP, SendGrid, AWS SES, Postmark
- IMAP Reading - Read inbox, search messages, mark as read/unread
- Multi-Account - Manage multiple email accounts with different providers
- Database:
email_accounts.db
Methods:
register_account(name, smtp?, imap?)- Register email accountsend_from(account, to, subject, body, ...)- Send emailread_inbox(account, limit?)- Read inbox messagessearch_messages(account, query, limit?)- Search emailsmark_as_read(account, message_id)- Mark message as readmark_as_unread(account, message_id)- Mark as unreadlist_accounts()- List all registered accountsremove_account(name)- Remove account
✅ Discord (v2.0.0)
- Message Sending - Send messages with embeds to any channel
- Gateway Support - Real-time event streaming (messages, joins, reactions)
- Guild Management - Manage servers, channels, roles, members
- Moderation - Kick, ban, timeout, role assignment
- Multi-Account - Run multiple Discord bots simultaneously
- Database:
discord_accounts.db
Account Management:
register_account(name, bot_token)- Register Discord botlist_accounts()- List registered botsremove_account(name)- Remove bot account
Messaging:
send_message(account, channel_id, content, embed?)- Send messageedit_message(account, channel_id, message_id, content, embed?)- Edit messagedelete_message(account, channel_id, message_id)- Delete messageget_messages(account, channel_id, limit)- Get message historyadd_reaction(account, channel_id, message_id, emoji)- Add reactionpin_message(account, channel_id, message_id)- Pin messageunpin_message(account, channel_id, message_id)- Unpin message
Guild/Server Management:
list_guilds(account)- List all guilds bot is inget_guild(account, guild_id)- Get detailed guild infolist_channels(account, guild_id)- List all channelslist_members(account, guild_id, limit)- List memberslist_roles(account, guild_id)- List roles
Channel Management:
get_channel(account, channel_id)- Get channel infocreate_channel(account, guild_id, name, channel_type, parent_id?)- Create channelmodify_channel(account, channel_id, name?, topic?, position?)- Modify channeldelete_channel(account, channel_id)- Delete channel
Member Management:
get_member(account, guild_id, user_id)- Get member infomodify_member(account, guild_id, user_id, nick?, roles?)- Modify memberkick_member(account, guild_id, user_id, reason?)- Kick memberban_member(account, guild_id, user_id, reason?, delete_message_days?)- Ban memberunban_member(account, guild_id, user_id)- Unban memberlist_bans(account, guild_id)- List all bans
Role Management:
create_role(account, guild_id, name, permissions?, color?)- Create rolemodify_role(account, guild_id, role_id, name?, permissions?, color?)- Modify roledelete_role(account, guild_id, role_id)- Delete roleadd_role_to_member(account, guild_id, user_id, role_id)- Add role to memberremove_role_from_member(account, guild_id, user_id, role_id)- Remove role from member
Thread Management:
create_thread(account, channel_id, name, message_id?)- Create threadjoin_thread(account, thread_id)- Join threadleave_thread(account, thread_id)- Leave thread
Webhooks:
create_webhook(account, channel_id, name)- Create webhook
Gateway (Real-time Events):
start_listening(account)- Start Gateway connection, stream live eventsstop_listening(account)- Stop Gateway connectionlist_active_listeners()- List bots currently listening
Gateway Events:
MessageReceived- New message posted (includes content, author, channel_id, guild_id)MessageUpdated- Message editedMessageDeleted- Message deletedMemberJoined- New member joined serverConnected- Bot connected to GatewayDisconnected- Connection lost
🚧 SMS (Planned)
- Twilio - SMS sending via Twilio API
- AWS SNS - SMS via Amazon SNS
- Multi-account support
🚧 Push Notifications (Planned)
- APNs - Apple Push Notification service
- FCM - Firebase Cloud Messaging (Android)
- Multi-device support
🚧 Telegram (Planned)
- Bot API - Send messages, inline keyboards, media
- Webhook Support - Receive updates
- Multi-bot support
🚧 WhatsApp (Planned)
- Business API - WhatsApp Business API integration
- Message Templates - Template-based messaging
🚧 Slack (Planned)
- Web API - Channel management, messaging
- Webhooks - Incoming webhooks
- Multi-workspace support
Quick Start
Installation
Add to your Cargo.toml:
[]
= { = "../plexus-comms" }
Basic Usage
use build_default_hub;
async
Running the Server
Server starts on ws://127.0.0.1:4445
Using with Synapse CLI
Email Example
# Register email account
# Send email
# Read inbox
Discord Example
# Register Discord bot
# Send message
# Create channel
# Start listening to events (real-time stream)
# List active listeners
# Stop listening
Architecture
Multi-Account Pattern
All activations follow a consistent multi-account pattern:
- Runtime Registration - Accounts are registered via API calls, not config files
- SQLite Storage - Account credentials stored in platform-specific databases
- Account-Based Methods - All methods accept an
accountparameter - Independent Operation - Each account operates independently
File Structure
plexus-comms/
├── src/
│ ├── activations/
│ │ ├── email/
│ │ │ ├── activation.rs # Email hub methods
│ │ │ ├── storage.rs # SQLite account storage
│ │ │ ├── smtp.rs # SMTP providers
│ │ │ ├── imap.rs # IMAP client
│ │ │ ├── types.rs # Email types & events
│ │ │ └── mod.rs
│ │ ├── discord/
│ │ │ ├── activation.rs # Discord hub methods
│ │ │ ├── storage.rs # SQLite account storage
│ │ │ ├── discord_client.rs # Discord API HTTP client
│ │ │ ├── discord_gateway.rs # Discord Gateway WebSocket client
│ │ │ ├── types.rs # Discord types & events
│ │ │ └── mod.rs
│ │ ├── sms/ # SMS activation (planned)
│ │ ├── push/ # Push notifications (planned)
│ │ ├── telegram/ # Telegram activation (planned)
│ │ ├── whatsapp/ # WhatsApp activation (planned)
│ │ ├── slack/ # Slack activation (planned)
│ │ └── mod.rs
│ ├── builder.rs # Hub builder
│ ├── config.rs # Configuration types
│ ├── lib.rs # Library exports
│ └── main.rs # Server entry point
├── Cargo.toml
└── README.md
Discord Gateway Architecture
The Discord Gateway implementation uses a modular, per-bot architecture:
- Independent Connections - Each bot account has its own WebSocket connection
- Concurrent Listening - Multiple bots can listen simultaneously
- Session Management - Automatic reconnection with session resuming
- Heartbeat System - Background task maintains connection health
- Event Streaming - Real-time events streamed via tokio channels
Gateway Manager:
Each start_listening call:
- Retrieves bot token from storage
- Spawns a Gateway task for that bot
- Maintains WebSocket connection with heartbeats
- Streams events to the caller
- Stores task handle for later shutdown
Configuration
Default Configuration
When no config file is present, plexus-comms starts with:
- Email activation (multi-account mode)
- Discord activation (multi-account mode)
Custom Configuration
Create config.toml:
[]
= "twilio"
= "ACXXXX"
= "your-token"
= "+1234567890"
[]
= "your-key-id"
= "your-team-id"
= "your-fcm-key"
[]
= "your-bot-token"
[]
= "ACXXXX"
= "your-token"
= "whatsapp:+1234567890"
[]
= "xoxb-your-token"
Then run:
Database Schema
Email Accounts (email_accounts.db)
(
name TEXT PRIMARY KEY,
smtp_config TEXT,
imap_config TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
Discord Accounts (discord_accounts.db)
(
name TEXT PRIMARY KEY,
bot_token TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
Dependencies
Core
plexus-core- Plexus RPC frameworkplexus-transport- WebSocket transport layertokio- Async runtimesqlx- Database access
lettre- SMTP clientasync-imap- IMAP clientasync-native-tls- TLS supporttokio-util- Compat layer for async I/O traits
Discord
reqwest- HTTP client for Discord APItokio-tungstenite- WebSocket for Discord Gatewayserde_json- JSON serialization
Building a Command Bot
To build a bot that reacts to Discord messages:
// Connect to plexus-comms and start listening
let events = discord.start_listening.await?;
// Process events
while let Some = events.next.await
Development
Building
Running Tests
Features
email-smtp- SMTP email sending (enabled by default)email-imap- IMAP email reading (enabled by default)
Discord Channel Types
0- Text channel2- Voice channel4- Category5- Announcement channel13- Stage channel15- Forum channel
Discord Permissions
Common permission values:
8- Administrator2048- Send Messages3072- Send Messages + Embed Links37080128- Read Messages + Send Messages + Read Message History104324673- Member (read, send, react, add reactions, use external emojis, read history)268435462- Moderator (manage messages, kick members, ban members, etc.)
License
MIT
Contributing
Contributions welcome! Please ensure all tests pass and follow the existing code structure.
Roadmap
- Email (SMTP + IMAP)
- Discord (API + Gateway)
- Discord message storage and CRUD
- SMS (Twilio, AWS SNS)
- Push Notifications (APNs, FCM)
- Telegram Bot API
- WhatsApp Business API
- Slack Web API
- Template system for messages
- Webhook receivers for incoming messages
- Rate limiting and retry logic
- Message queuing
- Analytics and logging