* Convert an SDK batch result entry to our BatchItemResult.
(entry: MessageBatchIndividualResponse)
| 188 | * Convert an SDK batch result entry to our BatchItemResult. |
| 189 | */ |
| 190 | function toBatchItemResult(entry: MessageBatchIndividualResponse): BatchItemResult { |
| 191 | const { custom_id, result } = entry; |
| 192 | |
| 193 | if (result.type === 'succeeded') { |
| 194 | return { |
| 195 | customId: custom_id, |
| 196 | status: 'succeeded', |
| 197 | message: (result as MessageBatchSucceededResult).message, |
| 198 | }; |
| 199 | } |
| 200 | |
| 201 | if (result.type === 'errored') { |
| 202 | const errResult = result as MessageBatchErroredResult; |
| 203 | // ErrorResponse.error is the ErrorObject containing type + message |
| 204 | const { type, message } = errResult.error.error; |
| 205 | return { |
| 206 | customId: custom_id, |
| 207 | status: 'errored', |
| 208 | error: { type, message }, |
| 209 | }; |
| 210 | } |
| 211 | |
| 212 | return { |
| 213 | customId: custom_id, |
| 214 | status: result.type as 'canceled' | 'expired', |
| 215 | }; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Extract the text content from a succeeded batch result. |