Created
September 12, 2022 14:36
-
-
Save ArnabXD/1287cce2827d64711f1575b734349326 to your computer and use it in GitHub Desktop.
GramJS - Get all links from message text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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