(
chatId: string,
filePath: string,
caption?: string,
replyTo?: string,
)
| 483 | } |
| 484 | |
| 485 | return this.channel.downloadResource(fileKey, type); |
| 486 | } |
| 487 | |
| 488 | private async sendFileSafe( |
| 489 | chatId: string, |
| 490 | filePath: string, |
| 491 | caption?: string, |
| 492 | replyTo?: string, |
| 493 | ): Promise<boolean> { |
| 494 | if (!this.channel) { |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | try { |
| 499 | if (!fs.existsSync(filePath)) { |
| 500 | console.error(`[Feishu] File not found for sending: ${filePath}`); |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | if (caption?.trim()) { |
| 505 | await this.sendSafe(chatId, caption, replyTo); |
| 506 | } |
| 507 | |
| 508 | const mimeType = detectMimeType(filePath); |
| 509 | if (isImageMime(mimeType)) { |
| 510 | await this.channel.send( |
| 511 | chatId, |
| 512 | { |
| 513 | image: { |
| 514 | source: filePath, |
| 515 | }, |
| 516 | }, |
| 517 | replyTo ? { replyTo } : undefined, |
| 518 | ); |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | await this.channel.send( |
| 523 | chatId, |
| 524 | { |
| 525 | file: { |
| 526 | source: filePath, |
| 527 | fileName: path.basename(filePath), |
| 528 | }, |
| 529 | }, |
| 530 | replyTo ? { replyTo } : undefined, |
| 531 | ); |
| 532 | return true; |
| 533 | } catch (error) { |
| 534 | console.error("[Feishu] Failed to send file:", error); |
| 535 | return false; |
| 536 | } |
| 537 | } |
no test coverage detected