BOTs (or robots) are used generally to answer prompt questions with some artificial intelligence, like directory assistance service - you ask the name, bot returns the phone number.
Developing a bot is easy. We need to get RTC Client API first which comes with RTCPresence sample application. In RTCPresenceCore.cs at RTCPresenceCore(IRTCPresenceUI presenceUI) you will find;
RTCPresenceCore(IRTCPresenceUI presenceUI)
// Set the event filterthis.client.EventFilter = RTCConst.RTCEF_REGISTRATION_STATE_CHANGE | ...
// Set the event filter
We need to add | RTCConst.RTCEF_MESSAGING to the above filter and also
| RTCConst.RTCEF_MESSAGING
this.client.IRTCClient2_ListenForIncomingSessions = RTC_LISTEN_MODE.RTCLM_BOTH;
this
before before the event handler registration, to let the application receive incoming IM messages. And OnRTCEvent is as follows;
OnRTCEvent
void OnRTCEvent(RTC_EVENT rtcEventType, object rtcEvent){ Trace.WriteLine("Entering RTCPresenceCore.OnRTCEvent " + rtcEventType); switch (rtcEventType) { case RTC_EVENT.RTCE_REGISTRATION_STATE_CHANGE: this.OnRTCRegistrationStateChangeEvent((IRTCRegistrationStateChangeEvent) rtcEvent); break; case RTC_EVENT.RTCE_CLIENT: this.OnRTCClientEvent((IRTCClientEvent)rtcEvent); break; case RTC_EVENT.RTCE_BUDDY: this.OnRTCBuddyEvent((IRTCBuddyEvent2)rtcEvent); break; case RTC_EVENT.RTCE_ROAMING: break; case RTC_EVENT.RTCE_PROFILE: this.OnRTCProfileEvent((IRTCProfileEvent2)rtcEvent); break; case RTC_EVENT.RTCE_PRESENCE_PROPERTY: break; case RTC_EVENT.RTCE_PRESENCE_DATA: break; default: break; }}
We need to add the following to switch statement that will enable the application to answer to incoming IM messages.
switch
case RTC_EVENT.RTCE_MESSAGING: this.OnRtcMessagingEvent((IRTCMessagingEvent)rtcEvent); break;
And answering them;
void OnRtcMessagingEvent(IRTCMessagingEvent rtcEvent){ string responseMessage; try { if (rtcEvent.EventType == RTC_MESSAGING_EVENT_TYPE.RTCMSET_MESSAGE){ responseMessage = ProcessRTCMessage(rtcEvent.Message); rtcEvent.Session.SendMessage("text/plain", responseMessage, 0); } } catch (Exception e) { Trace.WriteLine("Exception: "+ e.Message); }}
At ProcessRTCMessage the application reads, interperets and implements the message. For example it can return the first 5 search responses returned from MSN Search (using MSN Search API), or do a desktop search on file server (MSN Desktop Search API), or do a SQL search to return latest revenue details, etc. (up to your imagination).
ProcessRTCMessage