Skip to Content

SMS

ctx.SMS sends text messages. Use it to send a scan link, a reminder, or a result to a phone number. South African numbers go through SMS Portal, and every other country goes through Twilio.

Send one

const sent = await ctx.SMS.send({ to: "27821234567", content: "Your scan link is ready: https://scan.ollie.health/...", });

to is the number in international format. South African numbers can also be written +27… or 0….

Send a batch

Pass messages instead of to and content to send up to 500 at once.

await ctx.SMS.send({ messages: [ { destination: "27821234567", content: "Your results are ready." }, { destination: "27831234567", content: "Your results are ready." }, ], });

What comes back

ResultWhen
{ eventId }South African numbers, sent through SMS Portal.
{ messageIds }Every other number, sent through Twilio.
{ status: "pending_approval", approvalId, message }More than one number, when Bulk messages needs approval in Controls. The send happens when someone approves it.

Options

These apply to SMS Portal sends.

OptionTypeWhat it does
senderIdstringThe name or number the message comes from.
startDeliveryUtcstringSend later, at this time.
endDeliveryUtcstringStop trying to deliver after this time.
checkOptOutsbooleanSkip numbers that have opted out.
shortenUrlsbooleanShorten links in the message.
allowContentTrimmingbooleanTrim a message that is too long instead of failing.
campaignName, costCentrestringLabels for SMS Portal reports.
testModebooleanAccept the request without sending.
await ctx.SMS.send({ to: "27821234567", content: "Reminder: your follow-up scan is today.", options: { senderId: "Loops", checkOptOuts: true }, });

Credentials

South African sends use the loop’s SMS_PORTAL_CLIENT_ID and SMS_PORTAL_API_SECRET. Other countries use the loop’s TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_MESSAGING_SERVICE_SID or TWILIO_FROM_NUMBER. Set them as secrets. A loop without them uses the platform’s.

Example: text the results

import { workflow } from "@loops/sdk"; type ScanRequest = { patientId: string; phoneNumber: string }; export const healthScanWorkflow = workflow<ScanRequest>({ id: "health-scan", execute: async ({ step, event }) => { const { patientId, phoneNumber } = event.body; await step.do("Create the scan", async ({ ctx }) => { await ctx.FACIAL_SCAN.create({ metadata: { patientId, phoneNumber }, }); }); const scan = await step.waitForScan({ timeout: "30 minutes" }); await step.do("Text the results", async ({ ctx }) => { await ctx.SMS.send({ to: phoneNumber, content: `Your results are ready: ${await scan.pdfUrl()}`, }); }); }, });
Last updated on