Respond to an instant message

From libopenmetaverse - libomv - Developer Wiki

Jump to: navigation, search

// First, establish an event handler for the event that is fired when an instant message is received. Now your handler will be called whenever an IM is received.

       client.Self.OnInstantMessage += new AgentManager.InstantMessageCallback(Self_OnInstantMessage);


// Assume we want to respond with "hi yourself" if we receive an IM containing the word "hi". Use the session ID from the received message.

       private void Self_OnInstantMessage(InstantMessage im, Simulator simulator)
       {
           if (im.Message.Contains("hi"))
                 client.Self.InstantMessage(im.FromAgentID, "hi yourself", im.IMSessionID);
       }


// When we don't need to receive IM's any more, remove the event handler.

       client.Self.OnInstantMessage -= new AgentManager.InstantMessageCallback(Self_OnInstantMessage);


// Hope this helps.