Skip to content

Commit 1a0b496

Browse files
committed
feat(channels): add web channel support and enhance routing logic
- Introduced a new 'web' channel definition in MessagingPanel, allowing chat via the built-in web UI. - Updated channel connection state management to include the web channel, ensuring proper handling of connections. - Enhanced routing logic to support fallback mechanisms across all defined channels, improving resilience in connection handling. - Refactored channel type definitions to accommodate the new web channel, ensuring consistency across the application.
1 parent 8f95679 commit 1a0b496

5 files changed

Lines changed: 59 additions & 7 deletions

File tree

app/src/components/settings/panels/MessagingPanel.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ const FALLBACK_DEFINITIONS: ChannelDefinition[] = [
115115
],
116116
capabilities: ['send_text', 'receive_text', 'typing', 'threaded_replies'],
117117
},
118+
{
119+
id: 'web',
120+
display_name: 'Web',
121+
description: 'Chat via the built-in web UI.',
122+
icon: 'web',
123+
auth_modes: [
124+
{
125+
mode: 'managed_dm',
126+
description: 'Use the embedded web chat — no setup required.',
127+
fields: [],
128+
auth_action: undefined,
129+
},
130+
],
131+
capabilities: ['send_text', 'send_rich_text', 'receive_text'],
132+
},
118133
];
119134

120135
const MessagingPanel = () => {

app/src/lib/channels/routing.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type {
88

99
const SEND_PRIORITY: ChannelAuthMode[] = ['managed_dm', 'oauth', 'bot_token', 'api_key'];
1010

11+
const ALL_CHANNELS: ChannelType[] = ['telegram', 'discord', 'web'];
12+
1113
function isConnected(connection: ChannelConnection | undefined): boolean {
1214
return connection?.status === 'connected';
1315
}
@@ -17,6 +19,7 @@ export function resolvePreferredAuthModeForChannel(
1719
channel: ChannelType
1820
): ChannelAuthMode | null {
1921
const channelModes = state.connections[channel];
22+
if (!channelModes) return null;
2023
for (const authMode of SEND_PRIORITY) {
2124
if (isConnected(channelModes[authMode])) {
2225
return authMode;
@@ -35,9 +38,14 @@ export function resolveOutboundRoute(
3538
return { channel, authMode: mode };
3639
}
3740

38-
const fallbackChannel: ChannelType = channel === 'telegram' ? 'discord' : 'telegram';
39-
const fallbackMode = resolvePreferredAuthModeForChannel(state, fallbackChannel);
40-
if (!fallbackMode) return null;
41+
// Try other channels as fallback.
42+
for (const fallback of ALL_CHANNELS) {
43+
if (fallback === channel) continue;
44+
const fallbackMode = resolvePreferredAuthModeForChannel(state, fallback);
45+
if (fallbackMode) {
46+
return { channel: fallback, authMode: fallbackMode };
47+
}
48+
}
4149

42-
return { channel: fallbackChannel, authMode: fallbackMode };
50+
return null;
4351
}

app/src/store/channelConnectionsSlice.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const initialState: ChannelConnectionsState = {
2121
schemaVersion: SCHEMA_VERSION,
2222
migrationCompleted: false,
2323
defaultMessagingChannel: 'telegram',
24-
connections: { telegram: makeEmptyChannelModes(), discord: makeEmptyChannelModes() },
24+
connections: {
25+
telegram: makeEmptyChannelModes(),
26+
discord: makeEmptyChannelModes(),
27+
web: makeEmptyChannelModes(),
28+
},
2529
};
2630

2731
function touchConnection(
@@ -47,6 +51,7 @@ const channelConnectionsSlice = createSlice({
4751
if (state.migrationCompleted) return;
4852
state.connections.telegram = makeEmptyChannelModes();
4953
state.connections.discord = makeEmptyChannelModes();
54+
state.connections.web = makeEmptyChannelModes();
5055
state.defaultMessagingChannel = 'telegram';
5156
state.migrationCompleted = true;
5257
state.schemaVersion = SCHEMA_VERSION;

app/src/types/channels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type ChannelType = 'telegram' | 'discord';
1+
export type ChannelType = 'telegram' | 'discord' | 'web';
22

33
export type ChannelAuthMode = 'managed_dm' | 'oauth' | 'bot_token' | 'api_key';
44

src/openhuman/channels/controllers/definitions.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ impl ChannelDefinition {
150150

151151
/// Return the static registry of all supported channel definitions.
152152
pub fn all_channel_definitions() -> Vec<ChannelDefinition> {
153-
vec![telegram_definition(), discord_definition()]
153+
vec![
154+
telegram_definition(),
155+
discord_definition(),
156+
web_definition(),
157+
]
154158
}
155159

156160
/// Look up a channel definition by id.
@@ -248,6 +252,26 @@ fn discord_definition() -> ChannelDefinition {
248252
}
249253
}
250254

255+
fn web_definition() -> ChannelDefinition {
256+
ChannelDefinition {
257+
id: "web",
258+
display_name: "Web",
259+
description: "Chat via the built-in web UI.",
260+
icon: "web",
261+
auth_modes: vec![AuthModeSpec {
262+
mode: ChannelAuthMode::ManagedDm,
263+
description: "Use the embedded web chat — no setup required.",
264+
fields: vec![],
265+
auth_action: None,
266+
}],
267+
capabilities: vec![
268+
ChannelCapability::SendText,
269+
ChannelCapability::SendRichText,
270+
ChannelCapability::ReceiveText,
271+
],
272+
}
273+
}
274+
251275
#[cfg(test)]
252276
mod tests {
253277
use super::*;

0 commit comments

Comments
 (0)