-
Notifications
You must be signed in to change notification settings - Fork 170
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
Extract hyperlink from message #672
Comments
See Message entities |
You can parse the message to HTML and then extract links using regexp or the Cheerio DOM parser. import {HTMLParser} from 'telegram/extensions/html';
import * as cherrio from 'cheerio';
const html = HTMLParser.unparse(message, entities);
const $ = cherrio.load(html);
// => Work with DOM like jQuery to extract your links
// => $("a:contains('Your Anchor')").attr("href"); |
switch (history.className) {
case "messages.ChannelMessages":
for (const message of history.messages) {
switch (message.className) {
case "Message":
for (const entity of message.entities || []) {
switch (entity.className) {
case "MessageEntityUrl":
const url = message.rawText.slice(entity.offset, entity.offset + entity.length)
console.log(url)
break
}
}
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't find the way to extract a link from a hyperlink within a text from a message that was sent in a channel.
The text was updated successfully, but these errors were encountered: