Skip to content
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

Sanitize markdown before sending if the adapter is hubot-telegram #3

Open
gburgett opened this issue Jul 1, 2017 · 3 comments
Open

Comments

@gburgett
Copy link
Member

gburgett commented Jul 1, 2017

hubot help doesn't work with the Telegram adapter and a JS file containing this help header:

// Description:
//   Searches for query in wikia database. Looks in ingress subdomain by default. Set env var wikia_wiki to change subdomain.
//
//
// Configuration:
//   wikia_wiki
//
// Commands:
//   hubot wikia help - Returns a list of commands for this plugin
//   hubot wikia search [topic] <searchterm> - searches either on the ingress wikia or on a choosen wikia for the searchterm
//

Running hubot help produces this error

Bafplus 🇳🇱:
[Sat Jul 01 2017 14:13:01 GMT+0200 (CEST)] ERROR Error: Bad Request: can't parse entities in message text: Can't find end of the entity starting at byte offset 406
  at Function.TelegramBot.error (/home/server/hubot/node_modules/telegrambot/lib/telegrambot.js:26:15)
  at Request._callback (/home/server/hubot/node_modules/telegrambot/lib/telegrambot.js:47:66)
  at Request.self.callback (/home/server/hubot/node_modules/request/request.js:188:22)
  at emitTwo (events.js:106:13)
  at Request.emit (events.js:191:7)
  at Request.<anonymous> (/home/server/hubot/node_modules/request/request.js:1171:10)
  at emitOne (events.js:96:13)
  at Request.emit (events.js:188:7)
  at IncomingMessage.<anonymous> (/home/server/hubot/node_modules/request/request.js:1091:12)
  at IncomingMessage.g (events.js:292:16)
  at emitNone (events.js:91:20)
  at IncomingMessage.emit (events.js:185:7)
  at endReadableNT (_stream_readable.js:974:12)
  at _combinedTickCallback (internal/process/next_tick.js:80:11)
  at process._tickCallback (internal/process/next_tick.js:104:9)
@gburgett
Copy link
Member Author

gburgett commented Jul 1, 2017

The text produced in the shell adapter, which appears to cause the problem, is this:

Bafplus 🇳🇱:
lada help
lada> Shell: I can do a lot of things!  Which would you like to know more about? You can say:

* lada help cycle-times - Calculate Speticycle times.
* lada help nickname - Set your nickname
* lada help res-wikia - Searches for query in wikia database. Looks in ingress subdomain by default. Set env var wikia_wiki to change subdomain.
* lada help google-images - A way to interact with the Google Images API.
* lada help auth - Assign roles to users and restrict command access in other scripts.


Or you can see all commands by typing lada help all.

@gburgett
Copy link
Member Author

gburgett commented Jul 1, 2017

The issue is the mismatched underscore in the description. The telegram bot API refuses the message because it has a mismatched markdown element.

reproduce with:

curl -XPOST -H 'content-type: application/json' https://api.telegram.org/$TELEGRAM_TOKEN/sendMessage -d @/tmp/test.json

contents of /tmp/test.json should be

{ 
  "chat_id": 344335405,
  "text": "This unmatched_underscore breaks telegram markdown parsing",
  "reply_to_message_id": 8,
  "parse_mode": "Markdown"
}

@gburgett gburgett changed the title Telegram plugin issue with custom wikia hubot script Sanitize markdown before sending if the adapter is hubot-telegram Jul 1, 2017
@gburgett
Copy link
Member Author

gburgett commented Jul 1, 2017

If Telegram doesn't change their API I'm going to have to add some kind of sanitizer to escape the descriptions and commands before sending them to the telegram adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant