Intelligence, Advanced Charting & Trading Platform
risk/chartnova-seven-track-safety-2026-10-21
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | /** |
| 2 | * One-message Bale transport, injected HTTP client only. |
| 3 | * No automatic retries: timeout after send is ambiguous, never assert delivered. |
| 4 | * Secret bot token stays in ephemeral call argument, never returned or logged. |
| 5 | */ |
| 6 | const HOST='https://tapi.bale.ai'; |
| 7 | export async function baleOneMessage({token,chatId,text,transport}) { |
| 8 | if(typeof token!=='string'||!(/^[0-9]{4,20}:[a-zA-Z0-9_-]{12,180}$/).test(token)) |
| 9 | throw new TypeError('invalid private token supplied'); |
| 10 | if(typeof chatId!=='string'||!(/^[1-9][0-9]{0,15}$/).test(chatId)|| |
| 11 | BigInt(chatId)>BigInt(Number.MAX_SAFE_INTEGER)) |
| 12 | throw new TypeError('invalid positive private recipient id'); |
| 13 | if(typeof text!=='string'||text.length<1||text.length>1000) |
| 14 | throw new TypeError('invalid message length'); |
| 15 | if(typeof transport!=='function')throw new TypeError('inject transport explicitly'); |
| 16 | async function request(method,params){ |
| 17 | const url=HOST+'/bot'+token+'/'+method; |
| 18 | // Never report URL, request body, raw upstream response, stack trace or token. |
| 19 | const result=await transport(url,{method:'POST',headers:{'content-type':'application/json'}, |
| 20 | body:JSON.stringify(params),redirect:'error'}); |
| 21 | if(!result||result.status!==200)return null; |
| 22 | let data;try{data=await result.json()}catch{return null} |
| 23 | return data?.ok===true?data.result:null; |
| 24 | } |
| 25 | // Only positive numeric user IDs accepted; verify chat type immediately before send. |
| 26 | let chat; |
| 27 | try{chat=await request('getChat',{chat_id:chatId})} |
| 28 | catch{return {status:'FAILED',code:'PREFLIGHT_NETWORK_ERROR'}} |
| 29 | if(chat?.type!=='private'||String(chat.id)!==chatId) |
| 30 | return {status:'FAILED',code:'PRIVATE_RECIPIENT_UNVERIFIED'}; |
| 31 | let result; |
| 32 | try{result=await request('sendMessage',{chat_id:chatId,text})} |
| 33 | catch{return {status:'UNKNOWN',code:'DELIVERY_OUTCOME_UNKNOWN_NO_AUTO_RETRY'}}; |
| 34 | if(!Number.isSafeInteger(result?.message_id)||String(result?.chat?.id)!==chatId) |
| 35 | return {status:'UNKNOWN',code:'DELIVERY_OUTCOME_UNKNOWN_NO_AUTO_RETRY'}; |
| 36 | return {status:'SENT',code:'PROVIDER_ACCEPTED_NOT_READ',messageId:String(result.message_id)}; |
| 37 | } |