The messaging service API provides instant messaging functionality to the client application. Further, it takes care of retrieving data from the server, managing and performing business logic on this data and finally presenting it to the UI layer. It provides core instant messaging functions for clients served by AMM server:
The Messaging object is obtained from the Client SDK's User object. Start by obtaining any existing service configuration, enable the service and configure the AMM parameters supplied by your administrator. Refer to Configuring the SDK for more information. You can also follow attached examples below.
At the start it's necessary to prepare required data and objects. Create new CredentialProvider with 'username' and 'password' parameters:
var credentialProvider = new AvayaClientServices.Config.CredentialProvider('username', 'password');
The valid username and password are required to successfully register to the AMM server. Passwords are requested by and communicated to the Client SDK using the CredentialProvider interface. For more informations about credentials handling in Client SDK please refer to Working with Credentials.
Example configuration object with server data:
var config = {
ammConfiguration: {
enabled: true,
allowPrevalidation: true,
pollIntervalInMinutes: 1,
credentialProvider: credentialProvider,
networkProviderConfiguration: {
restConfig: {
hostName: "",
port: "",
isSecure: true
}
}
}
};
After you instantiate and set up any required configuration objects, you are now ready to create the User. Then you can get the Messaging for its further usage.
var messaging = user.getMessaging();
messaging instance will start together with User.start() method. It connects to the server from config object and listening is possible on addOnMessagingServiceAvailableCallback callback.
First, create new instance of Conversation object.
var newConversation = messaging.createConversation();
Then you can add participants to the Conversation by specifying a valid extension and domain.
var participants = ['participantAddress1', 'participantAddress2'];
newConversation.addParticipantAddresses(participants);
To get all conversations you can use Messaging.getActiveConversations() method on messaging api.
var conversations = messaging.getActiveConversations();
Once a Conversation has been created successfully, a new Message can be created and sent in the scope of the Conversation.
message = conversation.createMessage();
message.setBodyAndReportTyping(messageBody);
If a new Message has been received in the scope of the existing Conversation your application will be notified via addOnDataSetChangedCallback callback. The content of the received message should be added to active conversation.
var messages = conversations.getMessages();
messages.addOnDataSetChangedCallback(function() {
//Here you can get added message
});
Message is a crucial part of the Conversation. An important part of the Message is also attachments. You can attach Audio (".m4a"), Video (".mp4") and Pictures (".jpg") to your Message.
In order to create a new Attachment in a Message object, use the Message.createAttachment() method.
message.createAttachment(file);
To remove an Attachment from the Message use Message.removeDraftAttachment() method. You can also download the Attachment from the Message by using a getDownloadURL() method on attachment instance.