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
| Result | When |
|---|---|
{ 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.
| Option | Type | What it does |
|---|---|---|
senderId | string | The name or number the message comes from. |
startDeliveryUtc | string | Send later, at this time. |
endDeliveryUtc | string | Stop trying to deliver after this time. |
checkOptOuts | boolean | Skip numbers that have opted out. |
shortenUrls | boolean | Shorten links in the message. |
allowContentTrimming | boolean | Trim a message that is too long instead of failing. |
campaignName, costCentre | string | Labels for SMS Portal reports. |
testMode | boolean | Accept 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