lukefx / hubot-telegram

Hubot adapter for Telegram
MIT License
160 stars 42 forks source link

Markdown with Bad Entities #71

Open surfer190 opened 5 years ago

surfer190 commented 5 years ago

When the bot sends a message that has unclosed/invalid markdown and parse_mode is set to Markdown. An error is raised from the telegram api and the message is never sent.

This is a problem, as the message delivery should be our number 1 concern.

My proposal is that a check be made in the send function:

  ###*
  # Send a message to a specific room via the Telegram API
  ###
  send: (envelope, strings...) ->
    self = @
    text = strings.join()
    data = @applyExtraOptions({chat_id: envelope.room, text: text}, envelope.telegram);

    @apiSend data, (err, message) =>
      if (err)
        @robot.logger.debug "Error received: " + err
        found = err.search /entities/
        if (found > 0)
          # send the message again without markdown set
          ...
        self.emit 'error', err
      else
        self.robot.logger.info "Sending message to room: " + envelope.room

Please look over and add to this code if you think it is an acceptable way, if not let me know ways to improve it. Also, @gburgett if you have a minute please let me know your thoughts.