echo example

 

Echo example does the following:

  • in a supporter to supporter chat, it repeats everything you say to it, leaves when you leave
  • in a customer to supporter chat, when a supporter answers the chat, it automatically joins it and repeats everything the client says, as a comment (client said: ...), stays in the chat until the customer leaves

 

plugin.cpp

#include <windows.h>

#include <string.h>

#include <string>

#include <islprontoapi/islpronto_plugin.h>



void chat(void *, ISLProntoChatInfo info)

{

 ISLProntoStringCxx connid = ISLPronto->ConnectionInfoGetId(ISLPronto->ChatInfoAccessConnectionInfo(info));

 if(!connid)

         return;



 ISLProntoStringCxx chatid = ISLPronto->ChatInfoGetId(info);

 if(!chatid)

         return;



 // leave chat if no one is there to listen anymore

 if(ISLPronto->ChatInfoIAmOnlyOneInChat(info)) {

         ISLPronto->LeaveChat(connid.Get(), chatid.Get());

         return;

 }



 // join client chats, when there is also another supporter

 if(!ISLPronto->ChatInfoIAmMember(info)

         && ISLProntoStringCxx(ISLPronto->ChatInfoGetKey(info, ISLPRONTO_CHAT_INFO_CLIENT_CHAT)).NonEmpty())

 {

         if(ISLProntoStringSet users = ISLPronto->ChatInfoGetMemberUsers(info)) {

                 if(ISLPronto->StringSetSize(users) >= 1)

                         ISLPronto->JoinChat(connid.Get(), chatid.Get());

                 ISLPronto->FreeStringSet(users);

         }

 }

}



void message(void *, ISLProntoMessageInfo info)

{

 // messages get resent, if network connection to chat is (re)established, ignore them

 if(ISLPronto->MessageInfoIsReplay(info))

         return;



 // ignore my own messages

 if(ISLProntoUserInfo user_info = ISLPronto->MessageInfoAccessUserInfo(info))

         if(ISLPronto->UserInfoIsMyself(user_info))

                 return;



 ISLProntoStringCxx connid = ISLPronto->ConnectionInfoGetId(ISLPronto->MessageInfoAccessConnectionInfo(info));

 if(!connid)

         return;



 ISLProntoStringCxx chatid = ISLPronto->ChatInfoGetId(ISLPronto->MessageInfoAccessChatInfo(info));

 if(!chatid)

         return;



 ISLProntoStringCxx text = ISLPronto->MessageInfoGetKey(info, ISLPRONTO_MESSAGE_INFO_TEXT);

 if(!text || wcslen(text.AsWide()) == 0)

         return;



 if(ISLPRONTO_MESSAGE_TYPE_CLIENT == ISLPronto->MessageInfoGetType(info)) {

         // repeat all client messages in client chats

         std::wstring reply = L"client said: ";

         reply += text.AsWide();

         ISLProntoStringCxx reply_pronto(ISLPronto->StringFromWide(reply.c_str()));

         ISLPronto->Say(connid.Get(), chatid.Get(), reply_pronto.Get(), 1);

 } else if(!ISLProntoStringCxx(ISLPronto->ChatInfoGetKey(

                 ISLPronto->MessageInfoAccessChatInfo(info), ISLPRONTO_CHAT_INFO_CLIENT_CHAT)).NonEmpty())

 {

         // repeat everything in supporter chats

         ISLPronto->Say(connid.Get(), chatid.Get(), text.Get(), 0);

 }

}



void ISLProntoPluginStart()

{

 // uncomment if you wish to debug the plugin

 //ISLPronto->AttachDebugger();

 ISLPronto->RegisterChatEventHandler(chat, 0);

 ISLPronto->RegisterMessageEventHandler(message, 0);

}

ISLPRONTO_PLUGIN(ISLProntoPluginStart)

Was this article helpful?