mobivate/Mobivate.java


Blender BulkSMS Java XMLAPI Wrapper http://www.mobivate.com/bulksms

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.mobivate:Mobivate-Java:v.1.0.2'
	}
	dependencies {
		implementation("com.github.mobivate:Mobivate-Java:v.1.0.2")
	}
	<dependency>
	    <groupId>com.github.mobivate</groupId>
	    <artifactId>Mobivate-Java</artifactId>
	    <version>v.1.0.2</version>
	</dependency>

                            
    libraryDependencies += "com.github.mobivate" % "Mobivate-Java" % "v.1.0.2"
        
        

                            
    :dependencies [[com.github.mobivate/Mobivate-Java "v.1.0.2"]]
        
        

Readme


blender-api-java

Java interface for sending sms via Mobivate BulkSMS

Initialize the SDK

BulkXmlApi bulksms = new BulkXmlApi("USERNAME", "PASSWORD");

// Login
if (!bulksms.login()) {
    // Login incorrect
}

Send SMS to single recipient

// Send sms
XMLResponseWrapper response = bulksms.sendSingle(originator, recipient, body, routeId, reference);
// Get response
BatchRecipientMultiBody batchRec = (BatchRecipientMultiBody) response.getBody();
// Extract remote id
String remoteId = batchRec.getId();

see demo/Demo.php

Send same message to multiple recipients

// Create message and set basic params
BatchMessageSingleBody batch = new BatchMessageSingleBody();
batch.setOriginator(originator);
batch.setRouteId(routeId);
batch.setBody(body);

// Add multiple recipients
for (String recipient : recipients) {
    batch.addMSISDN(recipient);
}

// Submit message
XMLResponseWrapper xmlResponseWrapper = api.sendBatch(batch);
BatchMessageSingleBody response = (BatchMessageSingleBody) xmlResponseWrapper.getBody();

// Get batch and recipient message id's. 
String batchId = response.getId();
for (BatchRecipientSingleBody recipient : response.getRecipients()) {
    String recipientId = recipient.getId();
    System.out.println(recipient.getRecipient() + " remote id: " + recipientId);
}

Send multiple messages to multiple recipients

// Create message and set basic params
BatchMessageMultiBody batch = new BatchMessageMultiBody();
// Route id for recipients (default, override per recipient where needed)
batch.setRouteId(routeId);
// Originator for recipients (default)
batch.setOriginator(originator);
batch.setBody("Message Text, override per recipient where needed");

// Add recipients
batch.addRecipient(recipient1);
batch.addRecipient(recipient2, "another message");
batch.addRecipient(differentOriginator, recipient2, body, reference, differentRouteId);

// Submit message
XMLResponseWrapper xmlResponseWrapper = getApi().sendBatch(batch);
BatchMessageMultiBody response = (BatchMessageMultiBody) xmlResponseWrapper.getBody();

// Get batch and recipient message id's. 
String batchId = response.getId();
for (BatchRecipientMultiBody rcpt : response.getRecipients()) {
    String recipientId = recipient.getId();
    System.out.println(recipient.getRecipient() + " remote id: " + recipientId);
}

Schedule message

// Get date/time for send (one hour from now)
Date scheduleTime = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(scheduleTime);
cal.add(Calendar.MINUTE, 60);
scheduleTime = cal.getTime();

// Initialize message
BatchMessageSingleBody batch = new BatchMessageSingleBody();
batch.setOriginator(originator);
batch.setRouteId(routeId);
batch.setBody(body);

// Schedule time & timezone
batch.setDeliverySchedule(schedule);
batch.setDeliveryTimeZone(TimeZone.getDefault().getID());

// Add recipients, Submit message...

Receive SMS

String xml = request.getParameter("xml");
GenericXMLMarshaller<DeliveryMessage> marshaller = new GenericXMLMarshaller<DeliveryMessage>(DeliveryMessage.class);
DeliveryMessage message = marshaller.unmarshal(xml);

Receive Receipt

String xml = request.getParameter("xml");
GenericXMLMarshaller<DeliveryReceipt> marshaller = new GenericXMLMarshaller<DeliveryReceipt>(DeliveryReceipt.class);
DeliveryReceipt receipt = marshaller.unmarshal(xml);

String myRef = receipt.clientReference;
String recipientId = receipt.deliveryMessageId; 
String status = receipt.status;