An event that occurs when the server receives a private message from one user to another. When sending a private message via the function mSendPrivateMessage the event is not triggered to avoid looping.

 

Event template


function OnPrivateMessage(iCID, iUIN, iUINTo, iMsgType: integer; sMsg: string): boolean;
begin
  // your own code
  result := true;
end;
begin
end.


You can write any of your code instead of the comment.

 

Description of parameters

Parameter

Type

Value

iCID

integer

Client connection ID, unique session identifier in the online structure of network connections to the server;

iUIN

integer

unique identifier of a message sender (number >=0);

iUINTo

integer

unique identifier of a message recipient (number >=0);

iMsgType

integer

private message type;

sMsg

string

message text.

 

Return value

The function must return "true" by default. But if you decide to "suppress" a private message, you can return "false" and then the sent message will be deleted and won't display to the sender and recipient.

 

Example


const
  sHost     = 'mail.yourmailserver.com';
  sLogin    = 'support@yourmailserver.com';
  sPassword = 'yoursecretpassword';  
  iPort     = 25;
function OnPrivateMessage(iCID, iUIN, iUINTo, iMsgType: integer; sMsg: string): boolean;
var
  sEmailTo, sEmailFrom, sTextBody, sNameFrom, sNameTo: string;
begin
  result := true;
  
    if not mIsUINOnline(iUINTo) then begin
      sEmailTo := mGetUserPrimaryEmail(iUINTo);
      sEmailFrom := mGetUserPrimaryEmail(iUIN);
      
        if (length(sEmailTo)>0) and (length(sEmailFrom)>0) then begin
          sNameFrom := mGetUserFullNameByPreset(iUIN, 0);
          sNameTo := mGetUserFullNameByPreset(iUINTo, 0);
        
          sTextBody := FormatDateTime('[dd.mm.yyyy hh:nn:ss]', Now)+
                       ' '+
                       sNameFrom+
                       '> '+
                       mConvertMsgToPlainText(sMsg, iMsgType);
                         
          SendEmail(sHost, iPort, sLogin, sPassword, sEmailFrom, false, sEmailTo,
                    'Offline MyChat message for ' + sNameTo, sTextBody, 0, '');
        end;
    end;
end;
begin
end.


The script detects a user network status. If a user is offline, the script sends a message copy to this user email. All necessary data are taken from MyChat Server database.

 

For correct script work you need to fill the section of constants with parameters of your email server (host, login, password and port).

 

See also

FormatDateTime

mConvertMsgToPlainText

mGetUserFullNameByPreset

mGetUserPrimaryEmail

mIsUINOnline

Now

SendEmail