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