How to send to bulk sms numbers with twilio?

Hi there,

I am wondering if you know of a solution for sending bulk sms to multiple numbers in one workflow without having to do a lookup to a db/api and loop?

So a single request comes in with multiple numbers what would be the most efficient way (worker-wise) to solve this?

Here’s the working workflow for others:

Sourced from: https://community.n8n.io/t/create-multiple-items-with-map-function/4619

{
  "nodes": [
    {
      "parameters": {
        "from": "=+18444567891",
        "to": "=+1{{$node[\"Merge1\"].json[\"sms\"]}}",
        "message": "={{$node[\"Merge1\"].json[\"message\"]}}"
      },
      "name": "Twilio",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1540,
        240
      ],
      "credentials": {
        "twilioApi": {
          "id": "19",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "numbers",
              "value": "=+18441231234,+18443214321,+18441231024"
            },
            {
              "name": "message",
              "value": "New message"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        620,
        240
      ]
    },
    {
      "parameters": {
        "functionCode": "var arraylength = items[0].json.splitdata.length; \n\nfor (i=0; i<=arraylength; i++) { \n\nreturn items[0].json.numbers.split(\",\").map(sms => ({ json: { sms } }));\n\n}\n\n\n"
      },
      "name": "Create Multiple Items",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1060,
        240
      ]
    },
    {
      "parameters": {
        "functionCode": "var original = items[0].json.numbers;\n\nitems[0].json.splitdata = original.split(',');\n\nreturn items;\n"
      },
      "name": "Split Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        840,
        240
      ]
    },
    {
      "parameters": {
        "mode": "multiplex"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1280,
        240
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "message",
              "value": "={{$node[\"Set\"].json[\"message\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set3",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        960,
        420
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Split Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Set3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Multiple Items": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Data": {
      "main": [
        [
          {
            "node": "Create Multiple Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Twilio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set3": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}
1 Like