MyChat add-ons: developing, technical questions, testing, documentation and other useful information
User avatar
Alona Kutsenko
For example, some companies need to let users communicate with supervisors, but forbid the communication between sellers and accountants (however, they can write to other people from the common contact list).
This is a very complicated task, moreover, it can be much difficult in another company.

Of course, you want everything to work automatically on MyChat Server.

Starting from v.5.22 all necessary functions are added to the script engine, and it's easy to do by creating a script on the event OnPrivateRequest. We called it "PrivateRestrictionsByDepartments":
script-engine.png
script-engine.png (81.1 KiB) Viewed 5766 times


The code:

Code: Select all
function OnPrivateRequest(iCID, iUIN, iUINTo, iRole, iRoleReciever, iTask: integer): boolean;
var
  sDeptFrom, sDeptTo, sUserName: string;
  bFlag: boolean;
begin
  bFlag := true;
 
  // receive group names in the list of user contacts
  sDeptFrom := mGetUserDepartmentName(iUIN);
  sDeptTo   := mGetUserDepartmentName(iUINTo);
 
    // if a sender and recipient are located in the common contact list
    if (length(sDeptFrom) > 0) and (length(sDeptTo) > 0) then begin
      if sDeptFrom = 'Accountants' then begin
        // Accountants can write to anyone, except sellers     
        if sDeptTo = 'Sellers' then bFlag := false;
      end else
      if sDeptFrom = 'Sellers' then begin
        // Sellers can write to anyone, except accountants
        if sDeptTo = 'Accountants' then bFlag := false;
      end;
      //------------------------------------------------------------------
      if not bFlag then begin
        sUserName := mGetUserAttribute(iUINTo, 'DisplayName');
        mSendCustomMsgToClientConsoleByCID(iCID, 'You are not allowed to communicate with ' + sUserName,
                                           'Error', true, true, 74);
      end;                                                     
    end;
 
  result := bFlag;
end;

begin

end.


Ask your questions, share ideas and improvements.