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":
The code:
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.