How to send bulk SMS messages with Twilio Java SDK?



I’ve found plenty of information on how to send bulk of sms messages with Js, Python, PHP SDKs but nothing on how to achieve this using Java?

Here is a code snippet demonstrating the implementation for Python.

from twilio.rest import Client


account = "AC98e9a2817c2e0b4d38b42d1445ef42d9"
token = "your_auth_token"
client = Client(account, token)

notification = client.notify.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
   .notifications.create(
    to_binding=[
        "{"binding_type":"sms","address":"+15555555555"}",
        "{"binding_type":"facebook-messenger","address":"123456789123"}"
    ],
    body="Hello Bob")

Answer

Twilio developer evangelist here.

There is an example of sending bulk SMS messages with Java in the documentation for Twilio Notify.

Here is the example:

import java.util.Arrays;
import java.util.List;
import com.twilio.Twilio;
import com.twilio.rest.notify.v1.service.Notification;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static final String SERVICE_SID = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

  public static void main(String[] args) {
    // Initialize the client
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    List<String> toBindings = Arrays.asList(
    "{"binding_type":"sms","address":"+15555555555"}",
    "{"binding_type":"facebook-messenger","address":"123456789123"}");

    Notification notification = Notification
        .creator(SERVICE_SID)
        .setBody("Hello Bob")
        .setToBinding(toBindings)
        .create();

    System.out.println(notification.getSid());
  }
}


Source: stackoverflow