chore: update channel url (#13)

This commit is contained in:
paisley
2026-02-09 17:27:13 +08:00
committed by GitHub
Unverified
parent 05b5874832
commit 41b6868646
2 changed files with 31 additions and 21 deletions

View File

@@ -15,7 +15,7 @@ interface ChannelsState {
channels: Channel[]; channels: Channel[];
loading: boolean; loading: boolean;
error: string | null; error: string | null;
// Actions // Actions
fetchChannels: () => Promise<void>; fetchChannels: () => Promise<void>;
addChannel: (params: AddChannelParams) => Promise<Channel>; addChannel: (params: AddChannelParams) => Promise<Channel>;
@@ -32,7 +32,7 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
channels: [], channels: [],
loading: false, loading: false,
error: null, error: null,
fetchChannels: async () => { fetchChannels: async () => {
set({ loading: true, error: null }); set({ loading: true, error: null });
try { try {
@@ -136,7 +136,7 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
set({ channels: [], loading: false }); set({ channels: [], loading: false });
} }
}, },
addChannel: async (params) => { addChannel: async (params) => {
try { try {
const result = await window.electron.ipcRenderer.invoke( const result = await window.electron.ipcRenderer.invoke(
@@ -144,7 +144,7 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
'channels.add', 'channels.add',
params params
) as { success: boolean; result?: Channel; error?: string }; ) as { success: boolean; result?: Channel; error?: string };
if (result.success && result.result) { if (result.success && result.result) {
set((state) => ({ set((state) => ({
channels: [...state.channels, result.result!], channels: [...state.channels, result.result!],
@@ -177,36 +177,46 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
return newChannel; return newChannel;
} }
}, },
deleteChannel: async (channelId) => { deleteChannel: async (channelId) => {
// Extract channel type from the channelId (format: "channelType-accountId")
const channelType = channelId.split('-')[0];
try {
// Delete the channel configuration from openclaw.json
await window.electron.ipcRenderer.invoke('channel:deleteConfig', channelType);
} catch (error) {
console.error('Failed to delete channel config:', error);
}
try { try {
await window.electron.ipcRenderer.invoke( await window.electron.ipcRenderer.invoke(
'gateway:rpc', 'gateway:rpc',
'channels.delete', 'channels.delete',
{ channelId } { channelId: channelType }
); );
} catch (error) { } catch (error) {
// Continue with local deletion even if gateway fails // Continue with local deletion even if gateway fails
console.error('Failed to delete channel from gateway:', error); console.error('Failed to delete channel from gateway:', error);
} }
// Remove from local state // Remove from local state
set((state) => ({ set((state) => ({
channels: state.channels.filter((c) => c.id !== channelId), channels: state.channels.filter((c) => c.id !== channelId),
})); }));
}, },
connectChannel: async (channelId) => { connectChannel: async (channelId) => {
const { updateChannel } = get(); const { updateChannel } = get();
updateChannel(channelId, { status: 'connecting', error: undefined }); updateChannel(channelId, { status: 'connecting', error: undefined });
try { try {
const result = await window.electron.ipcRenderer.invoke( const result = await window.electron.ipcRenderer.invoke(
'gateway:rpc', 'gateway:rpc',
'channels.connect', 'channels.connect',
{ channelId } { channelId }
) as { success: boolean; error?: string }; ) as { success: boolean; error?: string };
if (result.success) { if (result.success) {
updateChannel(channelId, { status: 'connected' }); updateChannel(channelId, { status: 'connected' });
} else { } else {
@@ -216,10 +226,10 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
updateChannel(channelId, { status: 'error', error: String(error) }); updateChannel(channelId, { status: 'error', error: String(error) });
} }
}, },
disconnectChannel: async (channelId) => { disconnectChannel: async (channelId) => {
const { updateChannel } = get(); const { updateChannel } = get();
try { try {
await window.electron.ipcRenderer.invoke( await window.electron.ipcRenderer.invoke(
'gateway:rpc', 'gateway:rpc',
@@ -229,26 +239,26 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
} catch (error) { } catch (error) {
console.error('Failed to disconnect channel:', error); console.error('Failed to disconnect channel:', error);
} }
updateChannel(channelId, { status: 'disconnected', error: undefined }); updateChannel(channelId, { status: 'disconnected', error: undefined });
}, },
requestQrCode: async (channelType) => { requestQrCode: async (channelType) => {
const result = await window.electron.ipcRenderer.invoke( const result = await window.electron.ipcRenderer.invoke(
'gateway:rpc', 'gateway:rpc',
'channels.requestQr', 'channels.requestQr',
{ type: channelType } { type: channelType }
) as { success: boolean; result?: { qrCode: string; sessionId: string }; error?: string }; ) as { success: boolean; result?: { qrCode: string; sessionId: string }; error?: string };
if (result.success && result.result) { if (result.success && result.result) {
return result.result; return result.result;
} }
throw new Error(result.error || 'Failed to request QR code'); throw new Error(result.error || 'Failed to request QR code');
}, },
setChannels: (channels) => set({ channels }), setChannels: (channels) => set({ channels }),
updateChannel: (channelId, updates) => { updateChannel: (channelId, updates) => {
set((state) => ({ set((state) => ({
channels: state.channels.map((channel) => channels: state.channels.map((channel) =>
@@ -256,6 +266,6 @@ export const useChannelsStore = create<ChannelsState>((set, get) => ({
), ),
})); }));
}, },
clearError: () => set({ error: null }), clearError: () => set({ error: null }),
})); }));

View File

@@ -144,7 +144,7 @@ export const CHANNEL_META: Record<ChannelType, ChannelMeta> = {
icon: '🎮', icon: '🎮',
description: 'Connect Discord using a bot token from Developer Portal', description: 'Connect Discord using a bot token from Developer Portal',
connectionType: 'token', connectionType: 'token',
docsUrl: 'https://docs.openclaw.ai/channels/discord', docsUrl: 'https://docs.openclaw.ai/channels/discord#how-to-create-your-own-bot',
configFields: [ configFields: [
{ {
key: 'token', key: 'token',
@@ -255,7 +255,7 @@ export const CHANNEL_META: Record<ChannelType, ChannelMeta> = {
icon: '🐦', icon: '🐦',
description: 'Connect Feishu/Lark bot via WebSocket', description: 'Connect Feishu/Lark bot via WebSocket',
connectionType: 'token', connectionType: 'token',
docsUrl: 'https://docs.openclaw.ai/channels/feishu', docsUrl: 'https://docs.openclaw.ai/channels/feishu#step-1-create-a-feishu-app',
configFields: [ configFields: [
{ {
key: 'appId', key: 'appId',