MSL: mExtractExternalWebLinkFromMessage, get an external http(s) link on a file in a message
Get an external http(s) link on a file or image from a message to open or download them in a browser.
Syntax
function mExtractExternalWebLinkFromMessage(const sMsg: string; const iMsgType: integer): string;
Parameters and return values
Parameter |
Type |
Value |
sMsg |
string |
message body; |
iMsgType |
integer |
message type. |
Function result
If the message type MSG_TYPE_IMAGE or MSG_TYPE_FILE, then the function returns http/https link, if not then it returns an empty string.
Example
Sending a message to Telegram bot when a receiver of a private message is offline. Example from MyChat and Telegram integration. If the message type is a file or image and not a text, the bot receives a link on this file/image. An external address of MyChat WEB server is specified in a link, so Telegram can download a file and send it to a person subscribed to the bot's messages in the chat.
function OnPrivateMessage(iCID, iUIN, iUINTo, iMsgType: integer; sMsg: string): boolean;
var
sID, sOutMsg, sNameFrom, s: string;
bResult: boolean;
begin
SetScriptTimeOut(10000);
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);
if (iMsgType = 2) or (iMsgType = 23) then
sOutMsg := mExtractExternalWebLinkFromMessage(sMsg, iMsgType)
else
// 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
s := mIntegrationTelegramSendMessage(sID, sOutMsg, 5000);
bResult := true;
if JSONGetBoolean(s, 'ok', bResult) <> 0 then bResult := false;
// if any error occured - log result to server's system scripts protocol
if not bResult then begin
s := 'From: ' + IntToStr(iUIN) + ', to: ' + IntToStr(iUINTo) + CRLF + s;
mLogScriptToDisk(s);
end;
end;
end;
end;
begin
end.
See also
Processing MyChat Server events
Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator