| 114 | return resource.type === "image" || resource.type === "file"; |
| 115 | } |
| 116 | |
| 117 | export class FeishuAdapter implements PlatformAdapter, MessageSender { |
| 118 | readonly name = "feishu"; |
| 119 | |
| 120 | private channel: ResilientLarkChannel | null = null; |
| 121 | private agent: IPackAgent | null = null; |
| 122 | private ipcBroadcaster: IpcBroadcaster | null = null; |
| 123 | private rootDir = process.cwd(); |
| 124 | private readonly options: FeishuAdapterOptions; |
| 125 | |
| 126 | constructor(options: FeishuAdapterOptions) { |
| 127 | this.options = options; |
| 128 | } |
| 129 | |
| 130 | async start(ctx: AdapterContext): Promise<void> { |
| 131 | this.agent = ctx.agent; |
| 132 | this.ipcBroadcaster = ctx.ipcBroadcaster ?? null; |
| 133 | this.rootDir = ctx.rootDir; |
| 134 | const domain = normalizeFeishuDomain(this.options.domain); |
| 135 | |
| 136 | this.channel = createResilientLarkChannel({ |
| 137 | appId: this.options.appId, |
| 138 | appSecret: this.options.appSecret, |
| 139 | domain: resolveFeishuSdkDomain(domain), |
| 140 | loggerLevel: Lark.LoggerLevel.info, |
| 141 | transport: "websocket", |
| 142 | source: "skillpack", |
| 143 | policy: { |
| 144 | dmMode: "open", |
| 145 | requireMention: false, |
| 146 | }, |
| 147 | }); |
| 148 | |
| 149 | this.channel.on("message", (message) => { |
| 150 | void this.handleIncomingMessage(message).catch((error) => { |
| 151 | console.error("[Feishu] Error handling message:", error); |
| 152 | }); |
| 153 | }); |
| 154 | |
| 155 | this.channel.on("error", (error) => { |
| 156 | console.error("[Feishu] Channel error:", error); |
| 157 | }); |
| 158 | |
| 159 | this.channel.on("reconnecting", () => { |
| 160 | console.warn("[Feishu] Channel reconnecting"); |
| 161 | }); |
| 162 | |
| 163 | this.channel.on("reconnected", () => { |
| 164 | console.log("[Feishu] Channel reconnected"); |
| 165 | }); |
| 166 | |
| 167 | await this.channel.connect(); |
| 168 | const botName = this.channel.botIdentity?.name; |
| 169 | console.log( |
| 170 | botName |
| 171 | ? `[FeishuAdapter] Started as ${botName} (domain=${domain})` |
| 172 | : `[FeishuAdapter] Started (domain=${domain})`, |
| 173 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected