* 获取消息详情
(messageId: string)
| 251 | * 获取消息详情 |
| 252 | */ |
| 253 | async getMessage(messageId: string): Promise<FeishuMessageContext | null> { |
| 254 | try { |
| 255 | const response = (await this.client.im.message.get({ |
| 256 | path: { message_id: messageId }, |
| 257 | })) as { |
| 258 | code?: number; |
| 259 | msg?: string; |
| 260 | data?: { |
| 261 | items?: Array<{ |
| 262 | message_id?: string; |
| 263 | chat_id?: string; |
| 264 | msg_type?: string; |
| 265 | body?: { content?: string }; |
| 266 | sender?: { |
| 267 | id?: string; |
| 268 | id_type?: string; |
| 269 | sender_type?: string; |
| 270 | }; |
| 271 | create_time?: string; |
| 272 | }>; |
| 273 | }; |
| 274 | }; |
| 275 | |
| 276 | if (response.code !== 0 || !response.data?.items?.[0]) { |
| 277 | return null; |
| 278 | } |
| 279 | |
| 280 | const item = response.data.items[0]; |
| 281 | let content = item.body?.content ?? ''; |
| 282 | |
| 283 | // 解析消息内容 |
| 284 | try { |
| 285 | const parsed = JSON.parse(content); |
| 286 | if (item.msg_type === 'text' && parsed.text) { |
| 287 | content = parsed.text; |
| 288 | } |
| 289 | } catch { |
| 290 | // 保持原始内容 |
| 291 | } |
| 292 | |
| 293 | return { |
| 294 | messageId: item.message_id ?? messageId, |
| 295 | chatId: item.chat_id ?? '', |
| 296 | senderId: item.sender?.id ?? '', |
| 297 | senderOpenId: item.sender?.id_type === 'open_id' ? item.sender?.id ?? '' : '', |
| 298 | content, |
| 299 | contentType: item.msg_type ?? 'text', |
| 300 | chatType: 'p2p', // 需要通过其他方式获取 |
| 301 | mentionedBot: false, |
| 302 | }; |
| 303 | } catch (error) { |
| 304 | logger.error('Failed to get message', { messageId, error }); |
| 305 | return null; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * 更新消息 |
nothing calls this directly
no outgoing calls
no test coverage detected