(params: { chatId: string; text: string })
| 196 | } |
| 197 | |
| 198 | async sendTextMessage(params: { chatId: string; text: string }): Promise<void> { |
| 199 | const token = await this.getTenantAccessToken(); |
| 200 | |
| 201 | const res = await fetch( |
| 202 | 'https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id', |
| 203 | { |
| 204 | method: 'POST', |
| 205 | headers: { |
| 206 | authorization: `Bearer ${token}`, |
| 207 | 'content-type': 'application/json', |
| 208 | }, |
| 209 | body: JSON.stringify({ |
| 210 | receive_id: params.chatId, |
| 211 | msg_type: 'text', |
| 212 | content: JSON.stringify({ text: params.text }), |
| 213 | }), |
| 214 | }, |
| 215 | ); |
| 216 | |
| 217 | const json = (await res.json()) as any; |
| 218 | if (!res.ok || json?.code) { |
| 219 | throw new Error( |
| 220 | `feishu send error: http=${res.status} code=${json?.code} msg=${json?.msg}`, |
| 221 | ); |
| 222 | } |
| 223 | } |
| 224 | } |
no test coverage detected