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

Update for Telegram Bots 2.0 #102

Merged
merged 5 commits into from
Jun 6, 2016
Merged

Update for Telegram Bots 2.0 #102

merged 5 commits into from
Jun 6, 2016

Conversation

tjhorner
Copy link
Contributor

Telegram Bots 2.0!

I've added the new methods from the updated Bots API in Telegram. This includes all of the methods for kicking/banning users as well.

The APIs for kicking and unbanning chat members don't seem to work right now because it says the bots must be admins in the groups, but there's no way to make bots admins in groups quite yet. (unless I'm missing something...)

EDIT: It seems that the developers are aware that users cannot make bots admins and are fixing it. Personally, I think they're trying a slow rollout.

Methods added

@yagop
Copy link
Owner

yagop commented Apr 12, 2016

Nice, you were really quickly. 👏 👏 👏

Some test are needed. Maybe in some functions is almost impossible (the project doesn't have a mocked server) to test but others are.

@tjhorner
Copy link
Contributor Author

Sure, I'll add some tests when I get the time.

@fcuellom
Copy link

Very good work!!!
I've done something similar, but I added a parameter (show_alert) to the " answerCallbackQuery " function:

TelegramBot.prototype.answerCallbackQuery = function (callback_query_id, text, show_alert) { var form = {}; form.callback_query_id = callback_query_id; form.text = text; form.show_alert = show_alert; return this._request('answerCallbackQuery', {form: form}); };

Are you planning to pull the code?

Thanks in advance!

@tim427
Copy link

tim427 commented Apr 14, 2016

Hi @tjhorner ,

I've tried your pull-request, but receive the following error;

/home/tim/telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:17
class TelegramBot extends EventEmitter {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/tim/telegram-bot/node_modules/node-telegram-bot-api/index.js:1:80)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
error: Forever detected script exited with code: 1

Which node-version are you using?

@tjhorner
Copy link
Contributor Author

Seems to work for me, @tim427. It also doesn't seem related to my pull request, but I'm on v4.2.2.

@yagop yagop mentioned this pull request Apr 14, 2016
@ghost ghost mentioned this pull request Apr 17, 2016
@tjhorner
Copy link
Contributor Author

tjhorner commented Apr 18, 2016

Okay, you can now make bots admins in regular groups (not supergroups!) and kick chat members. You still can't unban them since you really can't ban users in regular groups. I'll push the tests soon.

image

@icdevin
Copy link

icdevin commented Apr 21, 2016

Doesn't it need to be modified in order to properly receive POSTs with callback_query data?
https://core.telegram.org/bots/api#getting-updates

Otherwise there's no way to really answer callback queries since the message is never received.

Also, at least basic documentation of the methods added.

@tjhorner
Copy link
Contributor Author

@icdevin You are correct, if you'd like to add that go ahead, but this PR isn't really at the top of my priority list. Also bots can be admined in supergroups now. I don't think I'll actually be able to write any of the tests soon, so if someone wants to take over that would be nice...

@icdevin
Copy link

icdevin commented Apr 25, 2016

Sure. I'll write the tests. Seems to be a pretty popular request. I'll need some time to do the group stuff as I haven't actually used it before but shouldn't be too difficult, I imagine. Thanks for your work thus far, @tjhorner.

What's the proper way to get my changes to this PR? I'd like to preserve your changes, of course. Should I make a PR to your branch?

@tjhorner
Copy link
Contributor Author

tjhorner commented Apr 25, 2016

That could work. If you fork my repo and checkout the bots-2.0 branch, it should preserve my changes and add yours to this PR.

The responses are pretty straightforward too, just check for an ok variable in the response that is non-falsy, I'd imagine, since that's how most of the others are.

@icdevin
Copy link

icdevin commented Apr 26, 2016

Does anyone else get a lot of timeouts when running the normal tests? I find a majority of them taking over the default 2000 ms threshold for failure. When I upped it to 5000 ms, all passed with the exception of two sendVideo tests. I'd like to set the default timeout for tests to 10,000 ms to account for a wider variety of network latencies. This is what they're doing over in Python Telegram Bot as well. @yagop?

@yagop
Copy link
Owner

yagop commented Apr 26, 2016

Just depends on you network speed and how bad are the Telegram servers. Currently I got 964ms on sendVideo, if you want you can pass --timeout to mocha, a PR is welcomed.

@SemihAkar
Copy link

when will the merge happen?

@icdevin
Copy link

icdevin commented May 1, 2016

I'm gonna try to finish this up in the next couple days. Sorry guys, been on vacation 😄!

@SemihAkar
Copy link

@icdevin thanks, we wait for it

- Adds support for callback_query-type messages
- Adds a showAlert option to answerCallbackQuery to more-closely align with the real bot API
- Adds tests for message editing functionality
- Adds a global test timeout of 10s and adds done() calls to all tests for assurance
@icdevin
Copy link

icdevin commented May 6, 2016

@yagop: Removed the extraneous done() calls.

@zigzag-way
Copy link

I updated my Node to the latest one:

node -p process.versions.v8
5.0.71.35
node -v
v6.1.0
... but still get errors:
node_modules\node-telegram-bot-api\src\telegram.js:20
static messageTypes = [
^
SyntaxError: Unexpected token =

Im sure its because of ES6... but dont understant how to fix it.

@phillipadsmith
Copy link

@zigzag-way Does this question have anything to do with this issue? If not, could you please open a new issue that's specific to your problem?

@zigzag-way
Copy link

I posted it here because I have the same problem as one of the guys posted here.

@zigzag-way
Copy link

And this problem is related with this Bot2.0 fork because it`s rewritten in ES6

@derhuerst
Copy link

@zigzag-way You could create an issue on the fork.

* @param {String} caption New caption of the message
* @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
* @return {Promise}
* @see https://core.telegram.org/bots/api#editmessagetext

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smmoosavi added a commit to monkey-patches/node-telegram-bot-api that referenced this pull request May 13, 2016
- add `all` option
- add `kickChatMember`, `unbanChatMember`,  `answerCallbackQuery`
- add `editMessageText`, `editMessageCaption`, `editMessageReplyMarkup`

related issue: yagop/node-telegram-bot-api#102
@tjhorner
Copy link
Contributor Author

tjhorner commented May 16, 2016

As it seems many people are having problems with this PR, I am going to make a new fork of the latest version of the library and try to implement it with as much compatibility as possible. I'll also add the listeners for callback requests and some of the functions I missed. I will most likely have time sometime this week.

I've also used this library for inline keyboards with some hacky stuff and the _request function and it has been working for me so I'll probably just merge that and make it better 😛 .

@SemihAkar
Copy link

When will the merge happen?

@Kaos1337
Copy link

For who needs a not ES6 version with bot 2.0, here there is what I use: https://github.com/Kaos1337/node-telegram-bot-api

@yagop yagop merged commit 270b3ef into yagop:master Jun 6, 2016
@yagop
Copy link
Owner

yagop commented Jun 6, 2016

Merged and published 0.22.0.

I'm really really sorry for not doing it before but I haven't too much time and has lost a bit of motivation.
Anyway it's merged now, enjoy and please forgive me if you can.

@yagop yagop mentioned this pull request Jun 6, 2016
@tjhorner
Copy link
Contributor Author

tjhorner commented Jun 6, 2016

No worries @yagop! I've just been using my local version for my projects for now.

@tjhorner tjhorner deleted the bots-2.0 branch June 6, 2016 21:12
@@ -110,6 +111,9 @@ class TelegramBot extends EventEmitter {
} else if (chosenInlineResult) {
debug('Process Update chosen_inline_result %j', chosenInlineResult);
this.emit('chosen_inline_result', chosenInlineResult);
} else if (callbackQuery) {
debug('Process Update callback_query %j', callbackQuery);
this.emit('callback_query', callbackQuery);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need mention in readme#Events

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

Successfully merging this pull request may close these issues.

None yet