@@ -22,7 +22,7 @@ import {
2222 resolveCrablineStateConversation ,
2323 resolveTelegramQaSenderId ,
2424} from "./crabline-provider-targets.js" ;
25- import { discardIgnoredResponseBody } from "./ignored-response-body.js" ;
25+ import { readQaJsonResponse } from "./ignored-response-body.js" ;
2626import {
2727 QaStateBackedTransportAdapter ,
2828 waitForQaTransportAccountReady ,
@@ -44,8 +44,6 @@ import type {
4444 QaBusOutboundMessageInput ,
4545} from "./runtime-api.js" ;
4646
47- const CRABLINE_TRANSPORT_ID = "crabline" ;
48-
4947type QaCrablineTransportState = QaTransportState & {
5048 cleanup : ( ) => Promise < void > ;
5149 getOutboundEvents : ( ) => Promise < readonly QaTransportOutboundEvent [ ] > ;
@@ -179,32 +177,23 @@ async function postCrablineInbound(params: {
179177 policy : { allowPrivateNetwork : true } ,
180178 auditContext : `qa-lab-crabline-${ params . adapter . channel } -inbound` ,
181179 } ) ;
182- try {
183- if ( ! response . ok ) {
184- await discardIgnoredResponseBody ( response ) ;
185- throw new Error (
186- `Crabline ${ params . adapter . channel } inbound injection failed with HTTP ${ response . status } .` ,
187- ) ;
188- }
189- const result : unknown = await response . json ( ) ;
190- if ( params . adapter . channel === "matrix" && isRecord ( result ) && isRecord ( result . event ) ) {
191- return readStringValue ( result . event . event_id ) ;
192- }
193- if ( params . adapter . channel === "slack" && isRecord ( result ) && isRecord ( result . message ) ) {
194- return readStringValue ( result . message . ts ) ;
195- }
196- if (
197- params . adapter . channel === "telegram" &&
198- isRecord ( result ) &&
199- isRecord ( result . update ) &&
200- isRecord ( result . update . message )
201- ) {
202- return normalizeStringifiedOptionalString ( result . update . message . message_id ) ;
203- }
204- return undefined ;
205- } finally {
206- await release ( ) ;
180+ const label = `Crabline ${ params . adapter . channel } inbound injection failed` ;
181+ const result = await readQaJsonResponse < unknown > ( response , release , label ) ;
182+ if ( params . adapter . channel === "matrix" && isRecord ( result ) && isRecord ( result . event ) ) {
183+ return readStringValue ( result . event . event_id ) ;
184+ }
185+ if ( params . adapter . channel === "slack" && isRecord ( result ) && isRecord ( result . message ) ) {
186+ return readStringValue ( result . message . ts ) ;
187+ }
188+ if (
189+ params . adapter . channel === "telegram" &&
190+ isRecord ( result ) &&
191+ isRecord ( result . update ) &&
192+ isRecord ( result . update . message )
193+ ) {
194+ return normalizeStringifiedOptionalString ( result . update . message . message_id ) ;
207195 }
196+ return undefined ;
208197}
209198
210199function createCrablineState ( params : {
@@ -317,7 +306,7 @@ class QaCrablineTransport extends QaStateBackedTransportAdapter {
317306 state : QaCrablineTransportState ;
318307 } ) {
319308 super ( {
320- id : CRABLINE_TRANSPORT_ID ,
309+ id : "crabline" ,
321310 label : `crabline local ${ params . selection . channel } ` ,
322311 accountId : params . adapter . accountId ,
323312 requiredPluginIds : params . adapter . requiredPluginIds ,
0 commit comments