Telegram 스폰서 메시지

· 기능

sgcWebSockets 2022.3.0부터 스폰서 메시지가 지원돼요. 스폰서 메시지는 Telegram 1.8.0 이상이 필요해서 Telegram 라이브러리가 이 기능을 지원하도록 업데이트됐어요.

Telegram의 스폰서 메시지는 구독자가 1000명 이상대규모 공개 일대다 채널에 표시되며 160자로 제한돼요. 스폰서 메시지는 표시되는 공개 채널의 주제에만 기반해요.

즉, 광고를 표시하기 위해 사용자 데이터를 채굴하거나 분석하지 않으며, Telegram에서 특정 채널을 보는 모든 사용자는 동일한 스폰서 메시지를 보게 돼요.

스폰서 메시지 가져오기 

 사용자가 채널을 열 때마다 이 채널에서 사용 가능한 스폰서 메시지를 받기 위해 channels.getSponsoredMessages를 호출해야 해요. 결과는 5분 동안 캐시해야 해요.

스폰서 메시지 표시 

스폰서 메시지는 채널의 다른 모든 게시물 아래, 사용자가 마지막 메시지를 지나 더 아래로 스크롤한 후에 표시돼야 해요. from_id 필드에 지정된 홍보 채널이나 봇이 메시지 작성자로 표시돼야 해요. 메시지에는 하단에 다음 버튼 중 하나가 포함돼야 해요.

예제 

아래는 sgcWebSockets 라이브러리를 사용해 스폰서 메시지를 요청하고 표시하는 예제예요.

//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');