Skip to content

Instantly share code, notes, and snippets.

@ArnabXD
Created September 12, 2022 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArnabXD/1287cce2827d64711f1575b734349326 to your computer and use it in GitHub Desktop.
Save ArnabXD/1287cce2827d64711f1575b734349326 to your computer and use it in GitHub Desktop.
GramJS - Get all links from message text
interface BaseTextEntities extends Record<string, unknown> {
offset: number;
length: number;
className: string;
}
type TextEntities = [BaseTextEntities, string];
export function filterUrls(entity: TextEntities[]): Array<string> {
return entity
.filter(([_e]) =>
["MessageEntityUrl", "MessageEntityTextUrl"].includes(_e.className)
)
.map(([_1, _2]) =>
_1.className === "MessageEntityUrl" ? _2 : (_1.url as string)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment