* 发送卡片消息
(
to: string,
card: Record<string, unknown>,
options?: { replyToMessageId?: string }
)
| 195 | * 发送卡片消息 |
| 196 | */ |
| 197 | async sendCardMessage( |
| 198 | to: string, |
| 199 | card: Record<string, unknown>, |
| 200 | options?: { replyToMessageId?: string } |
| 201 | ): Promise<FeishuSendResult> { |
| 202 | const content = JSON.stringify(card); |
| 203 | logger.debug('Sending card message', { content: content.substring(0, 500) }); |
| 204 | |
| 205 | try { |
| 206 | if (options?.replyToMessageId) { |
| 207 | const response = await this.client.im.message.reply({ |
| 208 | path: { message_id: options.replyToMessageId }, |
| 209 | data: { |
| 210 | content, |
| 211 | msg_type: 'interactive', |
| 212 | }, |
| 213 | }); |
| 214 | |
| 215 | if (response.code !== 0) { |
| 216 | logger.error('Card reply failed', { code: response.code, msg: response.msg, content: content.substring(0, 1000) }); |
| 217 | throw new Error(`Feishu card reply failed: ${response.msg || `code ${response.code}`}`); |
| 218 | } |
| 219 | |
| 220 | return { |
| 221 | messageId: response.data?.message_id ?? 'unknown', |
| 222 | chatId: to, |
| 223 | }; |
| 224 | } |
| 225 | |
| 226 | const response = await this.client.im.message.create({ |
| 227 | params: { receive_id_type: 'chat_id' }, |
| 228 | data: { |
| 229 | receive_id: to, |
| 230 | content, |
| 231 | msg_type: 'interactive', |
| 232 | }, |
| 233 | }); |
| 234 | |
| 235 | if (response.code !== 0) { |
| 236 | logger.error('Card send failed', { code: response.code, msg: response.msg, content: content.substring(0, 1000) }); |
| 237 | throw new Error(`Feishu card send failed: ${response.msg || `code ${response.code}`}`); |
| 238 | } |
| 239 | |
| 240 | return { |
| 241 | messageId: response.data?.message_id ?? 'unknown', |
| 242 | chatId: to, |
| 243 | }; |
| 244 | } catch (error) { |
| 245 | logger.error('Failed to send card message', { to, error }); |
| 246 | throw error; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * 获取消息详情 |
no outgoing calls
no test coverage detected