Skip to content

Normalize the telegram message #8

Description

@CDimonaco

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions