On MyChat Server you can determine user geographical position by their IP addresses. This feature is convenient for getting information about those people who write messages from website to chat.

 

The database has quite a large size and is not included in the MyChat Server default installer.

To enable GeoIP service you need:

 

  1. Stop MyChat Server, shut down his work.
  2. Download GeoIP database.
  3. Extract the archive to the C:\ProgramData\MyChat Server\integrations\geoip\ folder
  4. Launch MyChat Server.

 

Example of service usage

The script  is configured on the OnPrivateRequest event. The script determines which user is trying to open a session of private conversation, and if this is a user from a WEB support chat, the script sends information (including geographical position — city/country) about this user to an operator in private conversation.


function OnPrivateRequest(iCID, iUIN, iUINTo, iRole, iRoleReciever, iTask: integer): boolean;
var
  s,
  sCountry, sCity, sGeoIP,
  sIP,                            // remote user IP address
  sWEBSupportBrowserInfo,         // WEB-browser info
  sWEBSupportRefLink,             // reflink
  sWEBSupportsSysLanguage,        // browser locale language
  sWEBSupportsPlatformOS: string; // user's operation system
  
  iCIDTo: integer;
begin
  if mGetRoleNameByID(iRole) = 'WEB guests' then begin
    iCIDTo := mGetUserCID(iUINTo);
    
      if iCIDTo <> -1 then begin
        sIP                     := mGetCIDAttribute(iCID, 'IP');
        sWEBSupportBrowserInfo  := mGetCIDAttribute(iCID, 'UserAgent');
        sWEBSupportRefLink      := mGetCIDAttribute(iCID, 'Reflink');
        sWEBSupportsSysLanguage := mGetCIDAttribute(iCID, 'Lang');
        sWEBSupportsPlatformOS  := mGetCIDAttribute(iCID, 'OS');
    
        s := '---------------' + CRLF + 
             '-=WEB Support=-' + CRLF + CRLF + 
             'IP: ' + sIP;
      
          if length(sWEBSupportBrowserInfo) > 0 then s := s + CRLF + 'Browser: ' + sWEBSupportBrowserInfo + CRLF;
          if length(sWEBSupportRefLink) > 0 then s := s + CRLF + 'Reflink: ' + sWEBSupportRefLink;
          if length(sWEBSupportsSysLanguage) > 0 then s := s + CRLF + 'System language: ' + sWEBSupportsSysLanguage;
          if length(sWEBSupportsPlatformOS) > 0 then s := s + CRLF + 'OS: ' + sWEBSupportsPlatformOS;
          
        sGeoIP   := GeoIPGetQuickInfo(sIP);
        sCountry := Fetch(sGeoIP, '|');
        sCity    := sGeoIP;
        
          if length(sCountry) > 0 then begin
            sGeoIP := sCountry;
            
              if length(sCity) > 0 then sGeoIP := sGeoIP + ', ' + sCity;
              
            s := s + CRLF + CRLF + sGeoIP;  
          end else sGeoIP := '';  
      
        mSendPrivateMessage(iUIN, iUINTo, s, 21, true);
        mSendCustomMsgToClientConsoleByCID(iCIDTo, 'WEB support session from UIN ' + inttostr(iUIN), 'newmsg', false, true, 78);
      end;  
  end;
  result := true;
end;
begin
end.


Script work result

Website visitor connects to the support operator to ask questions in a browser:

User from a website in a browser

 

An operator receives a notification in MyChat Client (Windows version) and sees this person location:

Website visitor information for WEB support operator

 

Besides IP address, referral link, and information in a browser you can see a country and city after successful determination.

 

See also

How to configure a website chat?

REST API

Telegram

Delphi

Java

phpBB3

Network sockets