com.genesyslab.ail
Interface IMInteractionContext


public interface IMInteractionContext

Provides an interaction with Instant Messaging capabilities.
Instances of this class are available only for InteractionVoice of type MediaType.CHAT, to which they are tighly coupled. Managing the InteractionVoice instance for instant messaging is identical to managing a standard voice interaction.
Note: You need a Place configured with a SIP DN to handle this voice interaction.

To start an instant messaging session, your application should first create a voice interaction, then retrieve the context tight to this interaction, as shown in the following code snippet:

InteractionVoice sampleInteraction = (InteractionVoice) samplePlace.createInteraction(MediaType.CHAT, null, agentInteractionData.getQueue());

Your application can also get an IMInteractionContext instance by calling the AilFactory.getIMInteractionContext method, as shown here:

sampleContext = ailFactory.getIMInteractionContext(sampleInteraction);

Then to connect a party, make a call, as shown below:

sampleInteraction.makeCall( "SIP DNID", null, InteractionVoice.MakeCallType.REGULAR, null, null, null);

When your application gets a IMInteractionContext instance, it can retrieve all the session transcript, messages and party events by calling the getTranscript method. The following code snippet shows how to read the transcript.

Iterator it = sampleContext.getTranscript().iterator();
while (it.hasNext())
{     IMEvent ev = (IMEvent) it.next();
    // Process the event
    if( ev instanceof IMMessage)
    {
        IMMessage msg = (IMMessage) ev;
        IMParty party = msg.getParty();
        System.out.println(party.getNickname()+"> "+msg.getContent());
    }
     else if(ev instanceof IMPartyJoined)
     {
        System.out.println(ev.getParty().getNickname()+" has joined ");
     }
     else if(ev instanceof IMPartyLeft )
    {
        System.out.println(ev.getParty().getNickname()+"  has left ");
    }
}

At runtime, AIL provides two types of events that your application can handle by implementing the PlaceListener interface:

When your application is connected to parties and ready for sending and receiving instant messages, the Interaction.Status of your interaction changes to TALKING, as shown in the diagram below: .

To send a message, your application needs a call to sendMessage(java.lang.String, java.lang.String).

When your application receives a message, it gets an InteractionEvent and a PlaceEventIMInteractionContextInfo.

To terminate the instant messaging session, your application releases the voice interaction, then, marks it as done as shown here:

See Also:
InteractionVoice, IMEvent, PlaceEventIMInteractionContextInfo

Method Summary
 InteractionVoice getInteraction()
          Returns the interaction associated with this context.
 java.util.Map getParties()
          Returns the current parties of this IM chat session
 java.util.List getTranscript()
          Returns the transcript of this IM chat session
 void sendMessage(java.lang.String message, java.lang.String type)
          Sends a message to the parties of this IM chat session.
 

Method Detail

getInteraction

InteractionVoice getInteraction()
Returns the interaction associated with this context.


sendMessage

void sendMessage(java.lang.String message,
                 java.lang.String type)
Sends a message to the parties of this IM chat session.

Parameters:
message - the message to send.
type - the type of the message. Possible values are "text/plain" or "text/html".

getTranscript

java.util.List getTranscript()
Returns the transcript of this IM chat session

Returns:
a List of IMEvent.

getParties

java.util.Map getParties()
Returns the current parties of this IM chat session

Returns:
a Map of (String userID, IMParty).