W3C

The Messaging API

W3C Working Draft 10 August 2010

This version:
http://www.w3.org/TR/2010/WD-messaging-api-20100810/
Latest published version:
http://www.w3.org/TR/messaging-api/
Latest editor's draft:
http://dev.w3.org/2009/dap/messaging/
Editors:
Suresh Chitturi, Research in Motion
Daniel Coloma, Telefonica
Maria Angeles Oteo, Telefonica
Niklas Widell, Ericsson AB

Abstract

This specification defines an API that provides access to messaging functionality in the device, including SMS, MMS and email.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document represents the early consensus of the group on the scope and features of the proposed Messaging API; in particular, the group intends to work on messages management (move, delete, copy, etc.) in a separate specification.

Issues and editors note in the document highlight some of the points on which the group is still working and would particularly like to get feedback.

This document was published by the Device APIs and Policy Working Group as a First Public Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-device-apis@w3.org (subscribe, archives). All feedback is welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].

This specification defines conformance criteria that apply to a single product: user agents that implement the interfaces that it contains.

Since not all devices will have all messaging functionality (e.g. a phone may have only SMS and MMS while a PC may have only email) there is a need to indicate that conformant implementations need only expose available functionality.

Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification's terminology.

2. Introduction

The Messaging API defines a high-level interface to Messaging functionality, including SMS, MMS and Email. It includes APIs to create, send and receive messages.

The following code extracts illustrate how to create, send and receive messages.

Sending an SMS, if device supports it.

function successCB() {

   alert("The Message has been sent successfully");

}



function errorCB(error) {

   alert("The Message could not be sent " + error.code);

}



if (navigator.device.messaging.createSMS)

   navigator.device.messaging.createSMS({to: [{'+460000000001'}], body:

"Welcome to Atlantis"}).send(successCB, errorCB);

Register listener for new SMS events.

// function to receive new SMS notifications

function incomingSMS(message)

{

   alert("New incoming SMS from " + message.from);

   if (mySMSListener != null)

     navigator.device.messaging.unsubscribe(mySMSListener);

}

       

// Register listener for new SMS events

var mySMSListener = null;

mySMSListener = navigator.device.messaging.onSMS(incomingSMS);  	

3. Scope

This specification is limited to providing a scripting API for creating, sending and receiving messages. The supported messaging types include SMS, MMS and Email.

The specification does not replace RFCs for Mail or SMS URLs. The specification includes complementary functionality to these.

4. Security Considerations

The overall architecture for addressing privacy in DAP is still under construction. As it is finalized, there may be changes made to this API to reflect requirements or support for privacy-related functionality.

The API defined in this specification can be used to create and subscribe for incoming messages through different technologies.Sending messages usually have a cost associated to them, especially SMSs and MMSs. Furthermore this cost may depend on the message attributes (e.g. destination address) or external conditions (e.g. roaming status). Apart from billing implications, there are also privacy considerations due to the capability to access message contents. A conforming implementation of this specification must provide a mechanism that protects the user's privacy and this mechanism should ensure that no message is sent or no subscription is establisehd without the user's express permission.

4.1 Privacy considerations for implementors of the Messaging API

A user agent must not send messages or subscribe for incoming ones without the express permission of the user. A user agent must acquire permission through a user interface, unless they have prearranged trust relationships with users, as described below. The user interface must include the URI of the document origin, as defined in [HTML5]. Those permissions that are acquired through the user interface and that are preserved beyond the current browsing session (i.e. beyond the time when the browsing context, as defined in [HTML5], is navigated to another URL) must be revocable and a user agent must respect revoked permissions.

The methods that require user's express permission to be accessed are:

Obtaining once the user's express permission to access those methods does not imply the user has granted permission for later invocations of the same method or any other method provided by this API. This is especially important in the case of message sending, as every method invocation may lead to extra charges to the user.

A user agent may have prearranged trust relationships that do not require such user interfaces. For example, while a Web browser will present a user interface when a Web site request an SMS subscription, a Widget Runtime may have a prearranged, delegated security relationship with the user and, as such, a suitable alternative security and privacy mechanism with which to authorize that operation.

5. Supported messaging types

The specification supports three kinds of messages: SMS, MMS and E-mail. For each of them specific interfaces and data types have been defined and they will be detailed in the following section. The table below summarizes the attributes that are supported for each given message type.

Attribute SMS MMS Email
from X X X
timestamp X X X
folder X X X
account Id - - X
to X X X
cc - - X
bcc - - X
subject - X X
body X X X
attachments - X X
priority - - X

5.1 SMS specific concerns

Note that there are size limitations for SMSs sent on a network (the actual maximum size depends on language encoding the content). When an SMS exceeds the maximum size the device may divide the SMS into several parts. This means that one SMS object may lead to sending several ones to the network (if the platform supports multi-part SMSs).

6. API Description

6.1 DeviceMessaging

The DeviceMessaging object is exposed on the navigator.device object, as defined in [CORE-DEVICE].

Device implements DeviceMessaging;

All instances of the Device type are defined to also implement the DeviceMessaging interface.

[NoInterfaceObject]
interface DeviceMessaging {
    readonly attribute MessagingManager messaging;
};

6.1.1 Attributes

messaging of type MessagingManager, readonly
The root node from which the messaging functionality can be accessed.
No exceptions.

6.2 MessagingManager

This interface provides the general functionality that relates to messaging as well as the entry point for message creation and sending.

interface MessagingManager {
    SMSMessage   createSMS (in SMSProperties smsProperties);
    MMSMessage   createMMS (in MMSProperties mmsProperties);
    EmailMessage createEmail (in EmailProperties emailProperties);
    int          onSMS (in OnIncomingSMS messageEventCB);
    int          onMMS (in OnIncomingMMS messageEventCB);
    int          onEmail (in OnIncomingEmail messageEventCB);
    void         unsubscribe (in int subscriptionHandle);
};

6.2.1 Methods

createEmail
Creates a new EmailMessage object.
ParameterTypeNullableOptionalDescription
emailPropertiesEmailProperties The E-mail properties may include the "to", "cc", "bcc", "subject", "body", "accountId", "priority" and "attachments" attributes.
No exceptions.
Return type: EmailMessage
createMMS
Creates a new MMSMessage object.
ParameterTypeNullableOptionalDescription
mmsPropertiesMMSProperties The MMS properties may include the "to", "cc", "bcc", "subject", "body" and "attachments" attributes.
No exceptions.
Return type: MMSMessage
createSMS
Creates a new SMSMessage object.
ParameterTypeNullableOptionalDescription
smsPropertiesSMSProperties The SMS properties may include the "to" and "body" attributes.
No exceptions.
Return type: SMSMessage
onEmail
Registers the function to be notified on incoming new Emails. The function call returns a handle to the subscription
ParameterTypeNullableOptionalDescription
messageEventCBOnIncomingEmail The callback method for new Email events
No exceptions.
Return type: int
onMMS
Registers the function to be notified on incoming new MMSs. The function call returns a handle to the subscription
ParameterTypeNullableOptionalDescription
messageEventCBOnIncomingMMS The callback method for new MMS events
No exceptions.
Return type: int
onSMS
Registers the function to be notified on incoming new SMSs. The function call returns a handle to the subscription
ParameterTypeNullableOptionalDescription
messageEventCBOnIncomingSMS The callback method for new SMS events
No exceptions.
Return type: int
unsubscribe
Removes subscription for new messaging events.
ParameterTypeNullableOptionalDescription
subscriptionHandleint Handle to the subscription to be cancelled.
No exceptions.
Return type: void

6.3 SMSMessage

This interface describes generic functionality of SMS message.

[NoInterfaceObject]
interface SMSMessage : SMSProperties {
    readonly attribute DOMString id;
    readonly attribute Date      timestamp;
    readonly attribute DOMString from;
    readonly attribute DOMString folder;
    PendingOp send (in MessagingSuccessCB successCB, in optional MessagingErrorCB? errorCB);
};

6.3.1 Attributes

folder of type DOMString, readonly
A readonly folder indicating the place where the SMS is stored. Some possible values may be "inbox", "sent", "draft", "outbox" or "deleted".
No exceptions.
from of type DOMString, readonly
The MSIDN of the SMS sender.
No exceptions.
id of type DOMString, readonly
System set read-only unique identifier to assign to the SMS by the platform.
No exceptions.
timestamp of type Date, readonly
A readonly time stamp that detemines the time the SMS was received, sent or created.
No exceptions.

6.3.2 Methods

send
Asynchronous method to request sending an message. Upon a successful invocation the message is delivered to the nnetwork. The pendingOp returns object allows canceling the sending of the message.
ParameterTypeNullableOptionalDescription
successCBMessagingSuccessCB Function to call when the asynchronous operation completes.
errorCBMessagingErrorCB Function to call when the asynchronous operation fails.
No exceptions.
Return type: PendingOp

6.4 MMSMessage

This interface describes generic functionality of MMS message.

[NoInterfaceObject]
interface MMSMessage : MMSProperties {
    readonly attribute DOMString id;
    readonly attribute Date      timestamp;
    readonly attribute DOMString from;
    readonly attribute DOMString folder;
    PendingOp send (in MessagingSuccessCB successCB, in optional MessagingErrorCB? errorCB);
};

6.4.1 Attributes

folder of type DOMString, readonly
A readonly folder indicating the place where the MMS is stored. Some possible values may be "inbox", "sent", "draft", "outbox" or "deleted".
No exceptions.
from of type DOMString, readonly
The MSISDN of the MMS sender.
No exceptions.
id of type DOMString, readonly
System set read-only unique identifier to assign to the MMS by the platform.
No exceptions.
timestamp of type Date, readonly
A readonly time stamp that detemines the time the MMS was received, sent or created.
No exceptions.

6.4.2 Methods

send
Asynchronous method to request sending an message. Upon a successful invocation the message is delivered to the nnetwork. The pendingOp returns object allows canceling the sending of the message.
ParameterTypeNullableOptionalDescription
successCBMessagingSuccessCB Function to call when the asynchronous operation completes.
errorCBMessagingErrorCB Function to call when the asynchronous operation fails.
No exceptions.
Return type: PendingOp

6.5 EmailMessage

This interface describes generic functionality of E-mail message.

[NoInterfaceObject]
interface EmailMessage : EmailProperties {
    readonly attribute DOMString id;
    readonly attribute Date      timestamp;
    readonly attribute DOMString from;
    readonly attribute DOMString folder;
    PendingOp send (in MessagingSuccessCB successCB, in optional MessagingErrorCB? errorCB);
};

6.5.1 Attributes

folder of type DOMString, readonly
A readonly folder indicating the place where the Email is stored. Some possible values may be "inbox", "sent", "draft", "outbox" or "deleted".
No exceptions.
from of type DOMString, readonly
The address of the E-mail sender.
No exceptions.
id of type DOMString, readonly
System set read-only unique identifier to assign to the E-mail by the platform.
No exceptions.
timestamp of type Date, readonly
A readonly time stamp that detemines the time the SMS was received, sent or created.
No exceptions.

6.5.2 Methods

send
Asynchronous method to request sending an message. Upon a successful invocation the message is delivered to the nnetwork. The pendingOp returns object allows canceling the sending of the message.
ParameterTypeNullableOptionalDescription
successCBMessagingSuccessCB Function to call when the asynchronous operation completes.
errorCBMessagingErrorCB Function to call when the asynchronous operation fails.
No exceptions.
Return type: PendingOp

6.6 SMSProperties

This interface captures the data fields in an SMS message. See Supported Messaging Types for the list of attributes that must be supported for SMS type.

[NoInterfaceObject]
interface SMSProperties {
    attribute DOMString[] to;
    attribute DOMString   body;
};

6.6.1 Attributes

body of type DOMString
The message text body
No exceptions.
to of type array of DOMString
The set of addresses of the recipients. For SMS these are phone numbers.
No exceptions.

6.7 MMSProperties

This interface captures the data fields in an MMS message. See Supported Messaging Types for the list of attributes that must be supported for MMS type.

[NoInterfaceObject]
interface MMSProperties {
    attribute DOMString[] to;
    attribute DOMString   subject;
    attribute DOMString   body;
    attribute Blob[]      attachments;
};

6.7.1 Attributes

attachments of type array of Blob
The list of paths to attachments that will be sent together with the MMS
No exceptions.
body of type DOMString
The MMS text body
No exceptions.
subject of type DOMString
The MMS subject
No exceptions.
to of type array of DOMString
The set of addresses of the recipients. For MMS these may be phone numbers or e-mail addresses.
No exceptions.

6.8 EmailProperties

This interface captures the data fields in an E-mail message. See Supported Messaging Types for the list of attributes that must be supported for E-mail type.

[NoInterfaceObject]
interface EmailProperties {
    attribute DOMString[] to;
    attribute DOMString[] cc;
    attribute DOMString[] bcc;
    attribute DOMString   subject;
    attribute DOMString   body;
    attribute DOMString   accountId;
    attribute DOMString   priority;
    attribute Blob[]      attachments;
};

6.8.1 Attributes

accountId of type DOMString
Indicates the e-mail account ID/name associated with the message.
No exceptions.
attachments of type array of Blob
The list of paths to attachments that will be sent together with the e-mail
No exceptions.
bcc of type array of DOMString
The set of bcc (blind carbon copy) addresses of the recipients.
No exceptions.
body of type DOMString
The message text body
No exceptions.
cc of type array of DOMString
The set of cc (carbon copy) addresses of the recipients.
No exceptions.
priority of type DOMString
Delivery priority, the possible values are 'low', 'normal' (default) or 'high'.
No exceptions.
subject of type DOMString
The message subject
No exceptions.
to of type array of DOMString
The set of e-mail addresses of the recipients.
No exceptions.

6.9 OnIncomingSMS

This interface defines the method called on new SMS events.

[Callback=FunctionOnly, NoInterfaceObject]
interface OnIncomingSMS {
    c void onEvent (in SMSMessage message);
};

6.9.1 Methods

onEvent
This method is invoked when an SMS is received in the device.
ParameterTypeNullableOptionalDescription
messageSMSMessage
No exceptions.
Return type: c void

6.10 OnIncomingMMS

This interface defines the method called on new MMS events.

[Callback=FunctionOnly, NoInterfaceObject]
interface OnIncomingMMS {
    void onEvent (in MMSMessage message);
};

6.10.1 Methods

onEvent
This method is invoked when an MMS is received in the device.
ParameterTypeNullableOptionalDescription
messageMMSMessage
No exceptions.
Return type: void

6.11 OnIncomingEmail

This interface defines the method called on new MMS events.

[Callback=FunctionOnly, NoInterfaceObject]
interface OnIncomingEmail {
    void onEvent (in EmailMessage message);
};

6.11.1 Methods

onEvent
This method is invoked when an E-mail is received in the device.
ParameterTypeNullableOptionalDescription
messageEmailMessage
No exceptions.
Return type: void

6.12 MessagingSuccessCB

[Callback=FunctionOnly, NoInterfaceObject]
interface MessagingSuccessCB {
    void onSuccess ();
};

6.12.1 Methods

onSuccess
Invoked method when a successful messaging asynchronous call is received in the device.
No parameters.
No exceptions.
Return type: void

6.13 MessagingErrorCB

[Callback=FunctionOnly, NoInterfaceObject]
interface MessagingErrorCB {
    void onError (in MessagingError error);
};

6.13.1 Methods

onError
This interface defines the method invoked on failed messaging asynchronous calls defined in this API.
ParameterTypeNullableOptionalDescription
errorMessagingError
No exceptions.
Return type: void

6.14 MessagingError interface

Adds Messaging API specific error codes.

The MessagingError interface encapsulates all errors in the manipulation of Messaging objects in the messaging API.

[NoInterfaceObject]
interface MessagingError : GenericError {
    const unsigned short UNKNOWN_ERROR = 0;
    const unsigned short INVALID_ARGUMENT_ERROR = 1;
    const unsigned short NOT_FOUND_ERROR = 2;
    const unsigned short TIMEOUT_ERROR = 3;
    const unsigned short PENDING_OPERATION_ERROR = 4;
    const unsigned short IO_ERROR = 5;
    const unsigned short NOT_SUPPORTED_ERROR = 6;
    const unsigned short PERMISSION_DENIED_ERROR = 20;
    const unsigned short MESSAGE_SIZE_EXCEEDED = 30;
    readonly attribute unsigned short code;
};

6.14.1 Attributes

code of type unsigned short, readonly
An error code assigned by an implementation when an error has occurred in Messaging API processing.
No exceptions.

6.14.2 Constants

INVALID_ARGUMENT_ERROR of type unsigned short
An invalid parameter was provided when the requested method was invoked.
IO_ERROR of type unsigned short
An error occurred in communication with the underlying implementation that meant the requested method could not complete.
MESSAGE_SIZE_EXCEEDED of type unsigned short
The message that has been tried to be sent exceeds the maximum supported size for that message type.
NOT_FOUND_ERROR of type unsigned short
If no response information can be provided from the requested method.
NOT_SUPPORTED_ERROR of type unsigned short
The requested method is not supported by the current implementation.
PENDING_OPERATION_ERROR of type unsigned short
If the user agent is currently waiting for a callback on an asynchronous messaging operation, as defined in this specification.
PERMISSION_DENIED_ERROR of type unsigned short
Access to the requested method was denied at the implementation or by the user.
TIMEOUT_ERROR of type unsigned short
The requested method timed out before it could be completed.
UNKNOWN_ERROR of type unsigned short
An unknown error occurred.

A. Features for Future Consideration

This is a list of features that have been discussed with respect to this version of the API but for which it has been decided that if they are included it will be in a future revision.

ToDo

B. Acknowledgements

...

C. References

C.1 Normative references

[CORE-DEVICE]
Robin Berjon. Core Device Interfaces. 02 December 2009. W3C Editor's Draft. (Work in progress.) URL: http://dev.w3.org/2009/dap/device/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
[WEBIDL]
Cameron McCormack. Web IDL. 19 December 2008. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2008/WD-WebIDL-20081219

C.2 Informative references

[HTML5]
Ian Hickson; David Hyatt. HTML 5. 4 March 2010. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2010/WD-html5-20100304/