Skip to content

Commit

Permalink
feat: ability to show link preview above text
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jan 31, 2024
1 parent f008108 commit cb4a7dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gramjs/client/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export interface SendMessageParams {
/** A list of message formatting entities. When provided, the parseMode is ignored. */
formattingEntities?: Api.TypeMessageEntity[];
/** Should the link preview be shown? */
linkPreview?: boolean;
linkPreview?: boolean | { showAboveText: boolean};
/** Sends a message with a file attached (e.g. a photo, video, audio or document). The message may be empty. */
file?: FileLike | FileLike[];
/** Optional JPEG thumbnail (for documents). Telegram will ignore this parameter unless you pass a .jpg file!<br/>
Expand Down Expand Up @@ -551,7 +551,7 @@ export interface EditMessageParams {
/** A list of message formatting entities. When provided, the parseMode is ignored. */
formattingEntities?: Api.TypeMessageEntity[];
/** Should the link preview be shown? */
linkPreview?: boolean;
linkPreview?: boolean | { showAboveText: boolean};
/** The file object that should replace the existing media in the message. Does nothing if entity was a Message */
file?: FileLike;
/** Whether to send the given file as a document or not. */
Expand Down Expand Up @@ -735,6 +735,7 @@ export async function sendMessage(
noforwards: noforwards,
commentTo: commentTo,
topMsgId: topMsgId,
invertMedia: typeof linkPreview === 'object' ? linkPreview.showAboveText : false,
});
}
entity = await client.getInputEntity(entity);
Expand Down Expand Up @@ -785,6 +786,7 @@ export async function sendMessage(
entities: message.entities,
clearDraft: clearDraft,
noWebpage: !(message.media instanceof Api.MessageMediaWebPage),
invertMedia: typeof linkPreview === 'object' ? linkPreview.showAboveText : false,
scheduleDate: schedule,
noforwards: noforwards,
});
Expand All @@ -808,6 +810,7 @@ export async function sendMessage(
message: message.toString(),
entities: formattingEntities,
noWebpage: !linkPreview,
invertMedia: typeof linkPreview === 'object' ? linkPreview.showAboveText : false,
replyTo: replyObject,
clearDraft: clearDraft,
silent: silent,
Expand Down Expand Up @@ -977,6 +980,7 @@ export async function editMessage(
id,
message: text,
noWebpage: !linkPreview,
invertMedia: typeof linkPreview === 'object' ? linkPreview.showAboveText : false,
entities,
media: inputMedia,
replyMarkup: markup,
Expand Down
9 changes: 9 additions & 0 deletions gramjs/client/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ export interface SendFileInterface {
* Used for threads to reply to a specific thread
*/
topMsgId?: number | Api.Message;
/**
* Show media (usually link preview) on the top of message text
*/
invertMedia?: boolean;
}

interface FileToMediaInterface {
Expand Down Expand Up @@ -519,6 +523,7 @@ export async function _sendAlbum(
noforwards,
commentTo,
topMsgId,
invertMedia = false,
}: SendFileInterface
) {
entity = await client.getInputEntity(entity);
Expand Down Expand Up @@ -620,6 +625,7 @@ export async function _sendAlbum(
scheduleDate: scheduleDate,
clearDraft: clearDraft,
noforwards: noforwards,
invertMedia: invertMedia,
})
);
const randomIds = albumFiles.map((m) => m.randomId);
Expand Down Expand Up @@ -652,6 +658,7 @@ export async function sendFile(
noforwards,
commentTo,
topMsgId,
invertMedia = false,
}: SendFileInterface
) {
if (!file) {
Expand Down Expand Up @@ -682,6 +689,7 @@ export async function sendFile(
forceDocument: forceDocument,
noforwards: noforwards,
topMsgId: topMsgId,
invertMedia: invertMedia,
});
}
if (Array.isArray(caption)) {
Expand Down Expand Up @@ -734,6 +742,7 @@ export async function sendFile(
scheduleDate: scheduleDate,
clearDraft: clearDraft,
noforwards: noforwards,
invertMedia: invertMedia,
});
const result = await client.invoke(request);
return client._getResponseMessage(request, result, entity) as Api.Message;
Expand Down

0 comments on commit cb4a7dc

Please sign in to comment.