Search code examples
twiliovonage

Nexmo - Select from number based on location of destination to number


In Twilio there's an concept of phone # pools. A txt message can be sent using this Pools Id value and Twilio will select the best FROM number to send with. I've looked around Nexmos API's and I don't see similar capabilities, is this possible?

The only other option I've found is something call applications but I can't send messages without manually selecting the from numbers instead of automating it via application Id, I assume that would be one of the 'use cases'

There's a document from Nexmo https://help.nexmo.com/hc/en-us/articles/217571017-What-is-a-Sender-ID- that has the following

Random Numeric - Nexmo will apply a random number to comply with local regulations (usually taken from a pool of numbers we have access to from the relevant destination market).

Problem is how do I configure Random Numeric? It doesn't really explain and I might have missed those docs. Any suggestion help.


Solution

  • Random numeric is not something you set, is something the Nexmo API does in order to ensure delivery in certain parts of the world, in order to conform with local regulations.

    There is no Pools concept in Nexmo at the moment, so if you want the same functionality you'd have to build it in your code. Rent a bunch of Nexmo phone numbers, and then apply a random algorithm of choice in your code before sending each message to select your phone number. Something like:

    let myNexmoNumbers = [447481234567, 447481234568, 447481234569]
    
    nexmo.message.sendSms(myNexmoNumbers[Math.floor(Math.random() * myNexmoNumbers.length)], TO_NUMBER, TEXT_MESAGE, (err, responseData) => {
        if (err) {
            console.log(err);
        } else {
            if(responseData.messages[0]['status'] === "0") {
                console.log("Message sent successfully.");
            } else {
                console.log(`Message failed with error: ${responseData.messages[0]['error-text']}`);
            }
        }
    })