UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.08 kB
import{TwilioApiError,callTwilioApi as callTwilioApi$1,encodeTwilioForm,resolveTwilioCredential}from"#compiled/@chat-adapter/twilio/api.js";import{resolveTwilioAuthToken}from"#public/channels/twilio/verify.js";function twilioContinuationToken(e,t){return`${e}:${t??``}`}async function resolveTwilioAccountSid(t){try{return await resolveTwilioCredential(t,`TWILIO_ACCOUNT_SID`)}catch(t){throw t instanceof TwilioApiError&&t.status===0?Error(`TWILIO_ACCOUNT_SID is required.`):t}}async function callTwilioApi(e){let n=await resolveCredentials(e.credentials);return preserveTwilioApiResponse(callTwilioApi$1({apiBaseUrl:e.apiBaseUrl,body:encodeTwilioForm(e.body),credentials:n,fetch:e.fetch,path:e.path}))}async function sendTwilioMessage(e){if(!e.from&&!e.messagingServiceSid)throw Error(`twilioChannel: sending a message requires from or messagingServiceSid.`);let n=await resolveTwilioAccountSid(e.credentials?.accountSid),r=await resolveCredentials(e.credentials);return preserveTwilioApiResponse(callTwilioApi$1({apiBaseUrl:e.apiBaseUrl,body:encodeTwilioForm({Body:e.body,From:e.from,MessagingServiceSid:e.messagingServiceSid,StatusCallback:e.statusCallbackUrl,To:e.to}),credentials:r,fetch:e.fetch,path:`/2010-04-01/Accounts/${encodeURIComponent(n)}/Messages.json`}))}async function updateTwilioCall(e){let n=await resolveTwilioAccountSid(e.credentials?.accountSid),r=await resolveCredentials(e.credentials);return preserveTwilioApiResponse(callTwilioApi$1({apiBaseUrl:e.apiBaseUrl,body:encodeTwilioForm({Twiml:e.twiml}),credentials:r,fetch:e.fetch,path:`/2010-04-01/Accounts/${encodeURIComponent(n)}/Calls/${encodeURIComponent(e.callSid)}.json`}))}async function resolveCredentials(e){return{accountSid:await resolveTwilioAccountSid(e?.accountSid),authToken:await resolveTwilioAuthToken(e?.authToken)}}async function preserveTwilioApiResponse(t){try{return await t}catch(t){if(t instanceof TwilioApiError&&t.status!==0)return{body:t.body,ok:!1,status:t.status};throw t}}export{callTwilioApi,resolveTwilioAccountSid,sendTwilioMessage,twilioContinuationToken,updateTwilioCall};