Sending a private message on behalf of one user to another.

 

Syntax

function mSendPrivateMessage(iUINFrom, iUINTo: integer; sMsg: string; iMsgType: integer): integer;

 

Parameters and return values

Parameter

Type

Value

iUINFrom

integer

sender identifier. You can use the built-in bot (UIN 0) or any other registered user on the server;

iUINTo

integer

recipient identifier (UIN);

sMsg

string

message text. You can use line breaks (CRLF);

iMsgType

integer

private message type;

 

Function result

Result

Value

>0

all OK, message sent successfully; the result is a message index in the database;

-1

sender UIN does not exist;

-2

recipient UIN does not exist;

-3

message cannot be empty;

-4

message can't be sent to yourself.

 

Example

This function is linked to the OnPrivateRequest event. When trying to open a private conversation, the script determines, that a user came from the website, from the WEB support chat.

 

If a user came from WEB support chat for real, then the script sends a private message with the information about user IP, browser User Agent, local language, operating system and referral page, from which the user came from.

 

Script code is used by Network Software Solutions company in WEB support chat.

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
  SetScriptTimeOut(10000);
  
    if (mGetRoleNameByID(iRole) = 'WEB guests') and mIsUINOnline(iUINTo) 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);
  
      s := mGetCIDSByUINAndClientType(iUINTo, 'win32');
        
        while length(s) > 0 do begin
          iCIDTo := StrToInt(Fetch(s, ','));
          mSendCustomMsgToClientConsoleByCID(iCIDTo, 'WEB support session from UIN ' + inttostr(iUIN), 'newmsg', false, true, 78);
        end;  
    end;
  result := true;
end;
begin
end.


Script work result

Sending a private message from server script to MyChat Client (win32)
 

See also

CRLF

Fetch

GeoIPGetQuickInfo

IntToStr

Length

mGetUserAttribute

mGetCIDSByUINAndClientType

mGetRoleNameByID

mIsUINOnline

mSendCustomMsgToClientConsoleByCID
SetScriptTimeOut