Choose the channel

Pick the best channel for a message with one MobileValidate lookup: the first registered channel in your preference order, SMS as the fallback, voice for landlines.

Last updated

View as Markdown

This recipe picks a channel for each number with one lookup and several checks. It chooses the first channel in your preference order where the number is known to be registered, and falls back to SMS. The full code is in choose-channel.mjs.

How does it choose?

JavaScript
const ORDER = [
  { channel: "whatsapp", service: "whatsapp.registered" },
  { channel: "telegram", service: "telegram.registered" },
  { channel: "viber", service: "viber.registered" },
];

export function chooseChannel(row, order = ORDER) {
  if (row.number_status !== "valid") return { channel: "none", suggestion: row.suggestion };
  const unknown = [];
  for (const { channel, service } of order) {
    const c = row.checks?.[service];
    if (c?.registered === true) return { channel, unknown };
    if (!c || c.registered === null) unknown.push(channel);   // unknown is not "no"
  }
  if (row.checks?.["network.carrier"]?.attributes?.line_type === "fixed_line") return { channel: "voice", unknown };
  return { channel: "sms", unknown };
}

const { data } = await mv.lookup(numbers, { checks: ORDER.map((o) => o.service) });
const choices = data.results.map((row) => chooseChannel(row));

Put the channels in your own order, for example cheapest first. The unknown channels are reported separately, so you can retry later instead of recording "not registered".

How do I test it?

Shell
node choose-channel.mjs +447700900001 +447700900002 +447700900003
# +44••••••••01 → whatsapp
# +44••••••••02 → sms
# +44••••••••03 → sms (unknown: whatsapp, telegram, viber)

These are test values, so the command works with the public sandbox key. Platform names are used descriptively only; MobileValidate is not affiliated with these platforms.

Frequently asked questions

How many numbers can I check at once?

Up to 100 numbers per lookup. For bigger lists, use a bulk job.

Can I use this for marketing campaigns?

Use it to route messages people asked for, such as one-time codes, order updates and reminders. MobileValidate is not meant for unsolicited bulk messaging.