The telegram bot api, in each update, includes a message structure, we are interested in the entities section, in particular to the entities of type url and hashtag, the entities structure offers only the offset of entities, in the full text message.
So we should, take the original message, check for the entities, recover the full entities in the message text and create another data structure with only the relevant field and entities of the message.
We should pass the entity to the "validator", in order to check for valid links, as described in #1
Example
message {
message_id: 6,
from: {
id: 32970657,
is_bot: false,
first_name: 'Guabanal',
username: 'guabao',
language_code: 'en'
},
chat: {
id: 32970657,
first_name: 'Guabanal',
username: 'guabao',
type: 'private'
},
date: 1621790947,
text: 'ciao http://google.it #prova',
entities: [
{ offset: 5, length: 16, type: 'url' },
{ offset: 22, length: 6, type: 'hashtag' }
]
}
We can use telegraf as bot framework, but we will have the same message data structure
The
telegrambot api, in each update, includes a message structure, we are interested in the entities section, in particular to the entities of typeurlandhashtag, the entities structure offers only the offset of entities, in the full text message.So we should, take the original message, check for the entities, recover the full entities in the message text and create another data structure with only the relevant field and entities of the message.
We should pass the entity to the "validator", in order to check for valid links, as described in #1
Example
We can use
telegrafas bot framework, but we will have the same message data structure