Telegram | Sponsored Messages

Each time the user opens a channel, channels.getSponsoredMessages must be called to receive sponsored messages available for this channel. The result must be cached for 5 minutes.

 

Displaying sponsored messages

Sponsored messages must be displayed below all other posts in the channel, after the user scrolls futher down, past the last message. The promoted channel or bot specified in the from_id field must be displayed as the author of the message. The message should also contain one of the following buttons at the bottom:

 

 

Once the entire text is shown on the screen (excluding the button), ViewMessage method must be called with the random_id of this sponsored message.

 

Get Sponsored Messages

Send a request to the channel asking if there are sponsored messages available, just call the method GetChatSponsoredMessage.


oTelegram := TsgcTDLib_Telegram.Create(nil);
oTelegram.Telegram.API.ApiHash := 'ABCDEFGHIJKLMN';
oTelegram.Telegram.API.ApiId := '1234';
oTelegram.PhoneNumber := '008745744155';
oTelegram.Active := true;
oTelegram.getChatSponsoredMessage('100');

If the chat has sponsored messages, the event OnMessageSponsored is called with the content of the Sponsored message. If there are no messages, a 404 error is returned.


procedure(Sender: TObject; MessageSponsored: TsgcTelegramMessageSponsored);
begin
  DoLog(MessageSponsored.Text);
end;

Call the method ViewMethod after the Sponsored Messages has been shown to the user.


oTelegram.ViewMessage('100', '54653256245');