MCPcopy Create free account
hub / github.com/Hanson/claude-client / setupEventHandlers

Method setupEventHandlers

src/feishu/handler.ts:113–165  ·  view source on GitHub ↗

* 设置事件处理器

()

Source from the content-addressed store, hash-verified

111 * 设置事件处理器
112 */
113 private setupEventHandlers(): void {
114 // 处理消息接收事件
115 this.eventDispatcher.register({
116 'im.message.receive_v1': async (data: unknown) => {
117 try {
118 await this.handleMessageReceived(data as FeishuMessageEvent);
119 } catch (error) {
120 logger.error('Error handling message received event', { error, data });
121 }
122 },
123 });
124
125 // 处理机器人被添加到群聊事件
126 this.eventDispatcher.register({
127 'im.chat.member.bot_added_v1': async (data: unknown) => {
128 try {
129 const event = data as { chat_id: string; operator_id: { open_id: string } };
130 if (this.options.onBotAdded) {
131 await this.options.onBotAdded(event.chat_id, event.operator_id.open_id);
132 }
133 logger.info(`Bot added to chat: ${event.chat_id}`);
134 } catch (error) {
135 logger.error('Error handling bot added event', { error });
136 }
137 },
138 });
139
140 // 处理机器人被移除事件
141 this.eventDispatcher.register({
142 'im.chat.member.bot_deleted_v1': async (data: unknown) => {
143 try {
144 const event = data as { chat_id: string; operator_id: { open_id: string } };
145 if (this.options.onBotRemoved) {
146 await this.options.onBotRemoved(event.chat_id, event.operator_id.open_id);
147 }
148 logger.info(`Bot removed from chat: ${event.chat_id}`);
149 } catch (error) {
150 logger.error('Error handling bot removed event', { error });
151 }
152 },
153 });
154
155 // 处理卡片按钮点击事件
156 this.eventDispatcher.register({
157 'card.action.trigger': async (data: unknown) => {
158 try {
159 await this.handleCardAction(data as FeishuCardActionEvent);
160 } catch (error) {
161 logger.error('Error handling card action event', { error, data });
162 }
163 },
164 });
165 }
166
167 /**
168 * 处理接收到的消息

Callers 1

constructorMethod · 0.95

Calls 2

handleMessageReceivedMethod · 0.95
handleCardActionMethod · 0.95

Tested by

no test coverage detected