Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to show link preview above text #633

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading