MyChat Scripts: function mJoinUserToConf, connect a user to a conference
Add an online user to an existing conference. In the future, this user will be connected to a conference automatically until he leaves it or gets kicked out by a moderator.
Syntax
function mJoinUserToConf(const iUIN, iConfUID: integer): integer
Parameters and return value
Parameter |
Type |
Value |
iUIN |
integer |
user's identifier, above zero; he must be online; |
iConfUID |
integer |
existing conference ID. |
Function result
Result |
Value |
0 |
all OK, a user is connected to a conference; |
-2 |
a conference with a specified UID does not exist; |
-3 |
a user is already in this conference; |
-4 |
a user is disconnected from the server (offline); |
-5 |
a user is banned from entering this conference; |
-6 |
a user has no rights to join conferences; |
-7 |
a user with a specified UIN is not registered on the server; |
-8 |
incorrect password for entering a conference. |
Example
MyChat Guest user connects in a WEB browser to a conference, where he was invited to. He writes a message, but it turns out, that this conference has no members except him and built-in bot Elisa. Then a script looks for the first random online user from a specified group, automatically invites him to a conference, and generates a message on behalf of the bot saying he must reply to a client in a conference as soon as possible.
The script processes the event OnConfMessage.
const
ALARM_SUPPORT_GROUP = '?? ????????';
function OnConfMessage(iCID, iUIN, iUID, iMsgType: integer; sConfName, sMsg: string): boolean;
var
SL: TStringList;
sUsersList, sMsgTo: string;
iCount, iNewUIN: integer;
bFlag: boolean;
begin
if mGetCIDAttribute(iCID, 'ClientType') = 'mcguest' then begin
SL := TStringList.Create;
sUsersList := mGetConfUsersList(iUID);
SL.CommaText := sUsersList;
iCount := SL.Count;
if SL.IndexOf('0') <> -1 then dec(iCount);
SL.Free;
if iCount = 1 then begin // conference has no employees, someone's must be invited immediately
bFlag := false; // flag when at least on of the employees was notified
// than a conference with a customer is empty
sUsersList := mGetUsersListInGroupByName(ALARM_SUPPORT_GROUP);
while length(sUsersList) > 0 do begin
iNewUIN := StrToIntDef(Fetch(sUsersList, ','), -1);
if mIsUINOnline(iNewUIN) then begin
mJoinUserToConf(iNewUIN, iUID);
sMsgTo := 'Please, reply to a user ' +
mGetUserAttribute(iUIN, 'DisplayName') +
' in the conference "' + sConfName + '"';
// a message from a bot to an employee
// saying he must reply to a customer in the conference
mSendPrivateMessage(0, iNewUIN, sMsgTo, 1);
bFlag := true;
break;
end;
end;
end;
end;
result := true;
end;
begin
end.