// src/channel.ts
import type { ChannelPlugin, OpenClawConfig } from "openclaw/plugin-sdk";
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
type MyChatAccount = {
accountId: string;
enabled: boolean;
configured: boolean;
};
const meta = {
id: "mychat",
label: "MyChat",
selectionLabel: "MyChat Messenger",
blurb: "MyChat 即时通讯平台",
order: 100, // 在通道选择列表中的排序权重
};
export const myChatPlugin: ChannelPlugin<MyChatAccount> = {
id: "mychat",
meta,
// 能力声明——告诉 OpenClaw 这个通道支持什么
capabilities: {
chatTypes: ["direct", "group"], // 支持私聊和群聊
polls: false, // 不支持投票
reactions: false, // 不支持表情回复
threads: false, // 不支持线程
media: true, // 支持媒体(图片/文件)
},
// 配置适配器——账号管理
config: {
listAccountIds: () => [DEFAULT_ACCOUNT_ID],
resolveAccount: (cfg) => ({
accountId: DEFAULT_ACCOUNT_ID,
enabled: cfg.channels?.mychat?.enabled !== false,
configured: Boolean(cfg.channels?.mychat?.apiKey),
}),
defaultAccountId: () => DEFAULT_ACCOUNT_ID,
isConfigured: (account) => account.configured,
describeAccount: (account) => ({
accountId: account.accountId,
enabled: account.enabled,
configured: account.configured,
}),
resolveAllowFrom: ({ cfg }) =>
cfg.channels?.mychat?.allowFrom ?? [],
formatAllowFrom: ({ allowFrom }) =>
allowFrom.map((entry) => String(entry).trim().toLowerCase()).filter(Boolean),
setAccountEnabled: ({ cfg, enabled }) => ({
...cfg,
channels: {
...cfg.channels,
mychat: { ...cfg.channels?.mychat, enabled },
},
}),
deleteAccount: ({ cfg }) => {
const next = { ...cfg } as OpenClawConfig;
const nextChannels = { ...cfg.channels };
delete nextChannels.mychat;
next.channels = nextChannels;
return next;
},
},
// Gateway 适配器——消息监听
gateway: {
startAccount: async (ctx) => {
const { startMyChatMonitor } = await import("./monitor.js");
return startMyChatMonitor({
cfg: ctx.cfg,
abortSignal: ctx.abortSignal,
runtime: ctx.runtime,
log: ctx.log,
});
},
},
};