lukefx / hubot-telegram

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

Can't resolve an error #13

Closed idmitrievsky closed 9 years ago

idmitrievsky commented 9 years ago

Hi,

I keep getting an error: capture

Do you have any ideas how to fix it?

arcturial commented 9 years ago

Are you running the latest version of the bot? It looks like the telegrambot library is not passing the error message up to the hubot adapter, I will have a look at that.

I encountered this before when I used the wrong telegram authentication token or possibly when you are running your bot in "poll" mode while you have a webhook active.

arcturial commented 9 years ago

Found the issue, it happens when you are receiving a normal HTTP error instead of a Telegram error. This is most likely related to the wrong auth token, I will update the underlying library.

idmitrievsky commented 9 years ago

Do you mean that I could have copy-pasted my bot's token wrong?

I used this post to guide myself through installation.

arcturial commented 9 years ago

Yes, try and do an npm update to update the telegrambot dependency. It should now show the HTTP status code of non-Telegram errors. If the status code is 403, it means the auth token is wrong.

arcturial commented 9 years ago

Let me know what error code you receive after doing the update and I will try to assist.

idmitrievsky commented 9 years ago

Of course, sorry, I got busy with work :smile:

I updated telegrambot as you said, now hubot prints

[Wed Jul 22 2015 13:57:40 GMT-0400 (EDT)] INFO Telegram Adapter Started...
[Wed Jul 22 2015 13:57:41 GMT-0400 (EDT)] ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. `heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web_url | cut -d= -f2)`
[Wed Jul 22 2015 13:57:41 GMT-0400 (EDT)] INFO hubot-redis-brain: Using default redis on localhost:6379
[Wed Jul 22 2015 13:57:41 GMT-0400 (EDT)] ERROR Error:
  at Function.TelegramBot.error (/home/bot/ddbot/node_modules/hubot-telegram/node_modules/telegrambot/lib/telegrambot.js:26:15)
  at Request._callback (/home/bot/ddbot/node_modules/hubot-telegram/node_modules/telegrambot/lib/telegrambot.js:47:88)
  at Request.self.callback (/home/bot/ddbot/node_modules/hubot-telegram/node_modules/telegrambot/node_modules/request/request.js:198:22)
  at Request.emit (events.js:110:17)
  at Request.<anonymous> (/home/bot/ddbot/node_modules/hubot-telegram/node_modules/telegrambot/node_modules/request/request.js:1057:14)
  at Request.emit (events.js:129:20)
  at IncomingMessage.<anonymous> (/home/bot/ddbot/node_modules/hubot-telegram/node_modules/telegrambot/node_modules/request/request.js:1003:12)
  at IncomingMessage.emit (events.js:129:20)
  at _stream_readable.js:908:16
  at process._tickCallback (node.js:355:11)

The ERROR part loops until I kill it. I can't really see any error codes.

arcturial commented 9 years ago

Is telegrambot on version 0.0.11?

arcturial commented 9 years ago

also, do you run the bot like this:

TELEGRAM_TOKEN=asdb12341414141 bin/hubot -a telegram -n botname without wrapping the token in <> (stupid question, just checking)

idmitrievsky commented 9 years ago

Yeah, I exported TELEGRAM_TOKEN variable earlier, it echoes back and hubot shows it on initialisation, so no problems there :smile:

I'm just not familiar with npm and I am not exactly sure what I'm doing :disappointed: I finally reinstalled hubot-telegram to update it dependencies :blush: Now there is a new info in error explanations:

[Wed Jul 22 2015 14:21:32 GMT-0400 (EDT)] ERROR Error: HTTP status 403 returned.

You were right. What should I do?

arcturial commented 9 years ago

That means that your token isn't authenticating properly.

Try hitting this url:

https://api.telegram.org/bot[token]/getUpdates

Replace the [token] part with your token and see if you get a decent response back, if that doesn't work it means the token you exported is not valid.

idmitrievsky commented 9 years ago

I am sorry, turns out : in my token got replaced by ; and I didn't notice because of a bad font. All is working properly now. Thanks for your help! :+1:

idmitrievsky commented 9 years ago

I have to more questions though:

arcturial commented 9 years ago

For a more complete process mangement approach, look at something like forever.js from npm. It will keep your processes alive forever and start them up if they fail.

idmitrievsky commented 9 years ago

I feel maybe these questions should be in separate issues. However, they aren't really about hubot-telegram (well, maybe aliases problem is about Telegram).

arcturial commented 9 years ago

I will have a look at the alias issue, as for the process problem...you can pipe the output to a log file like so bin/hubot -a telegram -n name > log.file &

idmitrievsky commented 9 years ago

OK, thanks a lot! :relaxed: :+1:

arcturial commented 9 years ago

I found it, the issue you are running into with aliases is because of the https://core.telegram.org/bots#privacy-mode

It means that Telegram wont deliver messages unless it is directly send to the Telegram Bot user (when privacy mode is enabled). You can test this theory by running your command like this:

/@short_name help

The / character also works with privacy mode to indicate that bots should respond to the message. You can fix the problem by turning off privacy mode using their BotFather or prefixing all your instructions to the bot with /

idmitrievsky commented 9 years ago

Got it, thanks! Prefixing with / works like a charm.

Final question! :blush: Is there an easy way to restrict usage of my bot by other strangers?

arcturial commented 9 years ago

I currently have the same problem, you can probably deal with it in multiple ways

I wrote a custom "firewall" script for my personal needs, it blocks chats that don't belong to a predefined list of chatrooms.

module.exports = function (robot) {
    robot.hear(/(.*)/, function (res) {
        if (supportedRooms.indexOf(res.message.room) < 0) {
            res.message.done = true // <- stops other listeners from responding
            res.reply('you suck...I don't know you!');
        }
    });
}
idmitrievsky commented 9 years ago

OK, I see. It's not that hard after all, thanks! I think this info about privacy will be interesting to a lot of people – maybe add it to readme or something?

arcturial commented 9 years ago

Will do, thanks