MyChat Scripts Engine: mIntegrationTelegramGetUserIDByUIN, get a user's TelagramID by UIN
"For developers", "Server scripts", "Functions description", "Integrations", "Telegram", "mIntegrationTelegramGetUserIDByUIN".
Function to obtain Telegram user ID by his MyChat UIN.
Syntax
function mIntegrationTelegramGetUserIDByUIN(iUIN: integer): string;
Parameters and return values
Parameter |
Type |
Value |
iUIN |
integer |
MyChat user unique number. |
Function result
"-1" |
user with such UIN not found in the Telegram-MyChat table of user binds; |
"-2" |
user with such UIN is disabled and can't send messages to Telegram; |
another value |
Telegram user text ID that corresponds to the specified MyChat user UIN. |
Example
The script duplicates the private message to the Telegram user if MyChat user is offline at the moment. The script is linked to the OnPrivateMessage event.
function OnPrivateMessage(iCID, iUIN, iUINTo, iMsgType: integer; sMsg: string): boolean;
var
sID, sOutMsg, sNameFrom: string;
begin
result := true;
if not mIsUINOnline(iUINTo) then begin
// get sender's Telegram ID
sID := mIntegrationTelegramGetUserIDByUIN(iUINTo);
if sID[1] <> '-' then begin // no errors
// get MyChat sender's display name
sNameFrom := mGetUserFullNameByPreset(iUIN, 0);
// convert MyChat message to plaint text
sOutMsg := mConvertMsgToPlainText(sMsg, iMsgType);
// add WEB support link and user display name to message
sOutMsg := '' +
sNameFrom +
':' +
CRLF +
CRLF +
sOutMsg;
// send message to Telegram
mIntegrationTelegramSendMessage(sID, sOutMsg);
end;
end;
end;
begin
end.