Skip to content

Sending messages

Alexander Boldyrev edited this page Oct 31, 2024 · 25 revisions

With Mobile Messaging library you can send messages to arbitrary destinations from mobile device. These messages are also known as Mobile Originated (MO) messages.

MO messages sent from users' smartphone can be forwarded by our system to your own server. To activate the service please follow the configuration setup and action setup.

Once your server receives an MO message, it’s up to its logic to identify the message recipient (destination identifier) and what to do with data received from mobile devices. Destination identifier might be any string you choose to define as the wanted destination of your MO message.

NOTE: Please, follow the instructions linked above for configuring MO forward action. Without this configuration you won't be able to receive MO messages on your server.

Sending messages - mobile implementation

Sending messages with custom payload

Following example code shows how you can send MO message using Mobile Messaging library API:

//Swift
let customPayload = ["order_name": "pizza_capriciossa", 
                  "rushed_delivery": true, 
                  "coupon_number": 44869320]
let moMessage = MM_MOMessage(destination: <# destination identifier #>,
                          text: <# message text you want to send #>,
                          customPayload: customPayload)

MobileMessaging.sendMessages([moMessage]) { (messages, error) in
	// handle the error if one occurs
	
	if let messages = messages {
		for message in messages {
			if message.status == MM_MOMessageStatus.SentSuccessfully {
				//message sent successfully
			} else {
				//message sent with failure
			}
		}
	}
}
//Objective-C
NSDictionary *customPayload = @{@"order_name": @"pizza_capriciossa", 
                             @"rushed_delivery": @YES, 
                             @"coupon_number": @44869320};

MM_MOMessage *moMessage = [[MM_MOMessage alloc] initWithDestination: <# destination identifier #>
														 text: <# message text you want to send #>
												customPayload: customPayload];
[MobileMessaging sendMessages:@[moMessage] completion:^(NSArray<MM_MOMessage *> * messages, NSError * error) {
	// handle the error if one occurs

	for (MM_MOMessage *moMessage in messages) {
		if (moMessage.status == MM_MOMessageSentStatusSentSuccessfully) {
			//message sent successfully
		} else {
			//message sent with failure
		}
	}
}];

Message sending events

Mobile Messaging SDK supports following notifications MMNotificationMessagesWillSend and MMNotificationMessagesDidSend that posted through the NSNotificationCenter. More information about these and other notifications here: Library events.

Receiving messages - server implementation

After you've configured desired MO actions your server is able to receive sent inbound messages.

Troubleshooting

An error "Push MO route is not available for your account. Please contact your account manager." (HTTP status code 403) may be received in response to attempt to send a message from mobile device. Contact your account manager to address the issue.

Clone this wiki locally