* Send a file to the Slack channel/thread.
(
client: any,
route: SlackRoute,
filePath: string,
caption?: string,
)
| 856 | * Send a file to the Slack channel/thread. |
| 857 | */ |
| 858 | private async sendFileSafe( |
| 859 | client: any, |
| 860 | route: SlackRoute, |
| 861 | filePath: string, |
| 862 | caption?: string, |
| 863 | ): Promise<void> { |
| 864 | try { |
| 865 | if (!fs.existsSync(filePath)) { |
| 866 | console.error(`[Slack] File not found for sending: ${filePath}`); |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | const filename = path.basename(filePath); |
| 871 | const fileContent = fs.readFileSync(filePath); |
| 872 | |
| 873 | await client.files.uploadV2({ |
| 874 | channel_id: route.channel, |
| 875 | thread_ts: route.threadTs, |
| 876 | filename, |
| 877 | file: fileContent, |
| 878 | title: caption || filename, |
| 879 | initial_comment: caption || undefined, |
| 880 | }); |
| 881 | } catch (err) { |
| 882 | console.error("[Slack] Failed to send file:", err); |
| 883 | } |
| 884 | } |
| 885 | } |