Comments (5)
First of all, thank you for your awesome contribution here. Nice work!
The pull request you saw is not 100% functional, it was just an idea, and I think you already got the best of it. Indeed I do agree we could merge some functionalities.
have an easy way to write a method and have that automatically detected as a command and that particular method is run when the command is sent to the bot.
Agree, if we are combining decorators we could do something like this:
@bot.command
def hello(bot, message, args):
bot.sendMessage(message.chat_id, 'Hello World!')
or even
@bot.command
def hello(chat, message, args):
print message.text
chat.sendMessage('Hello World!) # chat object inherits bot object and self parse chat_id as arg
As a response be able to make use of the whole telegram api. Now and in the future. (E.G. send a video as response)
Not sure what you mean by that, but command_handler will be an additional layer to core library, devs can go either way by doing manual long polling or using command handler.
blocking statements should be handled by the command handler.
Agree, with a decorator to identify command functions.
If I run a bot it should run until I and only I stop it. and not when a error is raised in a command.
Partially agree, there should be an option for that. Imagine someone trying to run a bot with an invalid token not catching errors (remember logging is not a good thing to auto enable for libraries).
I want to be able to send arguments with my command
Sure.
def hello(chat, message, args):
One more thing. I've been thinking about in event driven architecture, telegram offers some events where we could turn into useful decorators, how so:
on.new_chat_participant
on.left_chat_participant
on.new_chat_title
on.new_chat_photo
on.delete_chat_photo
etc etc
I'm back home this long weekend so I'll be able to help, please feel free to ping me on telegram (@leandrotoledo).
Once again, thanks for your work here.
from python-telegram-bot.
First of all thank you! you are the one doing all the great work here.
Secondly, I am building my own bot and I have a weird bug where it just stops to receive messages after some time. I haven't had time to fully debug this. So I want to get this bug out first.
As a response be able to make use of the whole telegram api. Now and in the future. (E.G. send a video as response)
Not sure what you mean by that, but command_handler will be an additional layer to core library, devs can go either way by doing manual long polling or using command handler.
As I said I'm building a bot for myself and it needs to be able to respond with a location. #47 is not able to do this now.
Also, perhaps telegram will add a feature sendSmell in the future. and I want to make use of it without changing the command handler. #47 is also not able to do this now.
however these things are easy to change.
If I run a bot it should run until I and only I stop it. and not when a error is raised in a command.
Partially agree, there should be an option for that. Imagine someone trying to run a bot with an invalid token not catching errors (remember logging is not a good thing to auto enable for libraries).
Indeed it is true that a program should always stay debugable.
I want to be able to send arguments with my command
Sure.
def hello(chat, message, args):
Well this not exactly what I meant. I meant that I want the users of the bot to be able to sent arguments alongside a comment. But I do think an update or just a message object will be enough information to handle a command. But only text a user send won't be sufficient.
One more thing. I've been thinking about in event driven architecture, telegram offers some events where we could turn into useful decorators.
I think this is a really nice idea. Maybe you can even replace the getUpdates with some events. for example:
on.message_sent
I was also thinking of implementing a nice way to create to create a command with multiple messages. An Example of what I mean by that is for example the /setuserpic from BotFather.
first you send one message with /setuserpic then the bot sends you a message and the you send a second message with the picture.
This is the way telegram makes their own bots.
- user sends a message that starts with '/'.
- to bot sends a reply (optionally with information what it wants to receive).
- (optionally)
a. the user sends the message according to that information.
b. the user sends the message not according to that information.
a. if 3.a and no more messages are needed by the command then send exit message
b. if 3.a and some messages are still needed by the command then 2.
c. if 3.b send error message and 3.
I don't know how to do this and I haven't done much thinking about this problem but I want to share it because maybe someone already has some neat idea about this.
How I do this kind of things now is to make long command_ methods with and long indentations.
from python-telegram-bot.
Many thanks for the contribution.
I second @leandrotoledo idea on event driven architecture. data should be emitted by event handler, getUpdates, increment lastupdatedid and polling mechanism should be completely abstracted out from user.
an ideal event driven command handler should be completely handled by "Observer" design patterns. Library requests for listeners (callbacks) for a given action
def start_command_handler_function(bot, update):
#handle how start command should behave
def reset_command_handler_function(bot, update):
#handle how reset command should behave
def message_handler_function
# handle all the other messages, which are not command
def main():
bot = Bot("TOKEN")
bot.onCommand("start", start_command_handler_function)
bot.onCommand("reset", reset_command_handler_function)
bot.onMessage(message_handler_function)
bot.start(timeout=2)
if __name__ == "__main__":
main();
sample example (Implemented in c++)
https://github.com/reo7sp/tgbot-cpp/blob/master/include/tgbot/EventBroadcaster.h
https://github.com/reo7sp/tgbot-cpp/blob/master/include/tgbot/EventHandler.h
Thanks,
Naveen
from python-telegram-bot.
Regarding the EnhancedBot
, it's a nice idea, but it not only doesn't work with the Updater
, it conflicts with the Dispatcher
notion in Updater
.
It would be better to extend Dispatcher
in master
to add, for example, a method processUpdates()
that works synchronously like the one in EnhancedBot
.
Then we could add method decorators for the various types of handlers.
Synchronous bots can then use Dispatcher
directly, and threaded bots can use Updater.
from python-telegram-bot.
@jh0ker has implemented a really nice code for this feature request, many ideas match the discussion we had here, so I'll mark this one as obsolete. Please feel free to reopen in case I'm missing something.
Lastest version should be available by
$ pip install python-telegram-bot --upgrade
Also, some good kick off can be found here
https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/echobot2.py
from python-telegram-bot.
Related Issues (20)
- [FEATURE] Convenience Functionalty for `BusinessOpeningHours`
- ImportError: cannot import name 'Update' from 'telegram' HOT 6
- [QUESTION] running other coroutines along with run_poll HOT 2
- [Type Hinting] `EncryptedCredentials.decrypted_secret` is not properly annotated HOT 2
- [QUESTION] problem with reading timeout. HOT 2
- [BUG] `Message.reply_text` leads to `Message thread not found` HOT 9
- Spelled wrong
- My TeamViewer ID HOT 1
- [BUG] `App.post_stop` is called even if `App.stop` is not called
- My TeamViewer ID HOT 1
- [QUESTION] HOT 5
- [BUG] Getting text_markdown_v2 from message does not always work correctly when the message contains blockquote entities HOT 5
- [BUG] `InlineKeyboardMarkup` does not appear with `send_photo()` HOT 3
- [QUESTION] Get User "Typing" behavior HOT 2
- [FEATURE] API 7.3 HOT 3
- [BUG] Can't get the first example in the documentation to work HOT 3
- Typo in documentation
- [ERROR]"Unable to import 'Filters' from 'telegram.ext' in python-telegram-bot library" HOT 3
- Remove Functionality Deprecated by API 7.3
- [QUESTION] Having multiple CallbackQueryHandlers inside a ConversationHandler HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-telegram-bot.