HonkIOHonkIO

BlogGuides

Using an SMS API in Canada: from first test to first live text

One SMS integration followed from a test key to a live send: the calls to make, the refusals to handle, what ends up on the bill and the checklist before you switch keys.

This guide follows one integration, an app that texts people in Canada, from the first test message to the first live one. It uses the HonkIO SMS API and its Node.js SDK. If you are still comparing providers, start with Choosing an SMS provider in Canada instead.

Start with a test key

A HonkIO account has a test key (mk_test_) from the moment it is created, before you add a card or buy a number. A test send runs the same recipient checks as a live one: consent and opt-outs, reserved and undeliverable numbers, and the check that the number is Canadian. Nothing reaches a carrier and nothing is charged; the message is priced like a live one, then marked delivered. So the error handling you write against a test key is the error handling you ship.

HonkIO refuses a text to any number with no consent record on file, so the first call happens when the person agrees, and the send comes after. A verification code sent through HonkIO Verify is the one exception. What CASL asks you to record is covered in What CASL actually requires before you send a text.

ts
import { Honkio } from '@honkio/node'

const honkio = new Honkio(process.env.HONKIO_API_KEY) // mk_test_... while you build

// Once, when the person agrees: record how they agreed
const consent = await honkio.consents.create({
  phoneNumber: '+1613XXXXXXX',
  consentType: 'express',
  sourceDescription: 'Booking form opt-in checkbox',
  sourceIp: '203.0.113.1',
})
if (consent.error) throw new Error(consent.error.message)

// Then send, with a key that makes a retry safe
const { data, error } = await honkio.messages.send({
  from: '+1416XXXXXXX',
  to: '+1613XXXXXXX',
  body: 'Acme Dental: your cleaning is booked for Tuesday at 2 pm. Reply STOP to opt out.',
}, { idempotencyKey: 'booking-5521-confirmation' })
if (error) throw new Error(`${error.name}: ${error.message}`)
console.log(data.id, data.mode, data.status, data.segment_count)

Pass an idempotencyKey on every send. A retry without one can send the same text twice and charge you twice; with one, a retry returns the original message. After the send, each change of status (sent, then delivered, undelivered or failed) arrives as a signed webhook. Replies arrive as message.received, and a STOP reply also fires opt_out.recorded, so your own records can follow.

Handle the refusals

A refused send costs nothing and comes back with a code. Branch on the code, not only the HTTP status:

  • Consent, 451: NO_CONSENT, CONSENT_EXPIRED or OPT_OUT_BLOCKED. Record consent or leave the person alone; a retry gets the same answer
  • Destination, 422: NON_CANADIAN_NUMBER, RESERVED_DESTINATION, UNDELIVERABLE_NUMBER or NOT_A_MOBILE_NUMBER. Mark the contact and move on. Why HonkIO refuses dead and fictional numbers explains the last three
  • Limits, 429: DAILY_LIMIT_REACHED, RECIPIENT_RATE_LIMITED or NUMBER_RATE_LIMITED. Wait rather than loop; NUMBER_RATE_LIMITED says how long in retry_after_seconds
  • Carrier, 503: CARRIER_UNAVAILABLE. Retry with the same idempotency key

What ends up on the bill

  • Sent texts: billed per segment. One emoji, or one of many French accented letters, cuts a segment from 160 characters to 70, as Why one accent can triple your SMS bill shows
  • Received texts: billed per segment too, except STOP, START and HELP
  • Numbers: rent comes out of your balance each month, and a local number adds a one-time activation fee with its first month
  • Accepted but undelivered: once the carrier accepts a message, it normally stays charged

Rates are on the pricing page, and GET /v1/pricing returns them for code that estimates costs. Everything comes out of one prepaid balance in Canadian dollars.

Before you switch to a live key

  • Top up: a live key (mk_live_) answers 402 PAYMENT_REQUIRED until the first top-up
  • Verify your mobile: a live send, and buying a live number, need a verified mobile number on the account
  • Buy a number: a live send must come from a number your account owns, local or toll-free
  • Record consent again with the live key: consents and opt-outs are kept per key mode, as Test and live, now for consent too explains
  • Expect the daily cap: a new account can send 250 live messages per rolling 24 hours, and can ask for more 30 days after its first live message

The SMS quickstart has each step in more detail, and the SDKs cover Node.js, Python, PHP and Laravel. Your messages and consent records are stored in Canada, and HonkIO is home says what that does and does not cover.

Send your first message this afternoon.