ali-toosi / django-tgbot Goto Github PK
View Code? Open in Web Editor NEWDjango app for creating Telegram bots
License: MIT License
Django app for creating Telegram bots
License: MIT License
How do I handle callbacks for inline keyboards? I tried to check documentation regarding this topic i didn't find it from the link .
Here is what I would like to achieve, if a user presses any button the bot knows which button was pressed and do something with it. Here is my code snippet so far.
@processor(state_manager,success='asked_to_select_main_menu_options')
def main_manu_options(bot: TelegramBot, update: Update, state: TelegramState):
chat_id = update.get_chat().get_id()
bot.sendMessage(
chat_id,
text='What would you like to do?',
reply_markup=InlineKeyboardMarkup.a(
inline_keyboard=[
[
InlineKeyboardButton.a('PK',callback_data='PK'),
],
[
InlineKeyboardButton.a('SP', callback_data='SP')
],
[
InlineKeyboardButton.a('LR',callback_data='LR')
],
[
InlineKeyboardButton.a('R',callback_data='R')
],
[
InlineKeyboardButton.a('Bill',callback_data='B')
]
]
)
)
Hello, thank you for this good library;
I have a problem working with images that the user sends
I noticed that the get photo method does not exist in the message, I added it and I was able to access the ID file. After that I got it with the get file method, but now I want to do two things but I can not:
1- Save the image in another location
2. Add this image to a field in the model that is of type imagefeild
The error I get:
`
File "C:\envsi\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\envsi\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\envsi\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "G:\sicheck3\testsicbot\views.py", line 24, in handle_bot_request
raise e
File "G:\sicheck3\testsicbot\views.py", line 21, in handle_bot_request
bot.handle_update(update)
File "C:\envsi\lib\site-packages\django_tgbot\bot.py", line 38, in handle_update
processor(self, update, db_state)
File "C:\envsi\lib\site-packages\django_tgbot\decorators.py", line 22, in function_runner
func(bot=bot, update=update, state=state, *args, **kwargs)
File "G:\sicheck3\testsicbot\processors\submit_signal.py", line 128, in submit_signal_taeed_adad
s.save()
File "C:\envsi\lib\site-packages\django\db\models\base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\envsi\lib\site-packages\django\db\models\base.py", line 763, in save_base
updated = self._save_table(
File "C:\envsi\lib\site-packages\django\db\models\base.py", line 842, in _save_table
values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
File "C:\envsi\lib\site-packages\django\db\models\base.py", line 842, in
values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
File "C:\envsi\lib\site-packages\django\db\models\fields\files.py", line 300, in pre_save
if file and not file._committed:
`
my code:
`image = update.get_message().get_photo()
tt=bot.getFile(image[-1].file_id)
s = DarafSignalModel.objects.get(chatid =chatid)
s.image = tt
s.save()`
Obviously, the problem is s.save, but when I delete it, nothing is stored in my model !!!
please help me
Such as:
project
|- apps
| |- app1
| |- app2
|- bots
| |- foobot
| |- barbot
|- settings.py
|- manage.py
# settings.py
TGBOT_BASE_DIR = os.path.join(settings.BASE_DIR, 'bots')
# tgbotwebhook.py:L16
dst = os.path.join(settings.TGBOT_BASE_DIR, bot_username)
error after create bot app
m1, python3,
(venv_attendance) (base) baltschun@baltschuns-MacBook-Air app % python manage.py migrate
pygame 2.0.1 (SDL 2.0.14, Python 3.8.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 86, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/loader.py", line 274, in build_graph
raise exc
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/loader.py", line 248, in build_graph
self.graph.validate_consistency()
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/graph.py", line 195, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/graph.py", line 195, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/Users/baltschun/project/ananas/venv_attendance/lib/python3.8/site-packages/django/db/migrations/graph.py", line 58, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration ananas_attendance_onlybot.0002_auto_20201109_1648 dependencies reference nonexistent parent node ('botdevtestbot', '0001_initial')
How to use /command type of text from telegram? Like /start or /help
This is related to another issue about notification style messages. However, this issue is more specific, which hopefully makes the development easier.
The functionality that I propose sounds rather straightforward: Some kind of option, maybe associated with processors, that if activated will send a message directly after the state has changed rather than only as an answer to a user message.
One way might be to simulate user input somehow, but I have not found out so far how to do this and it sounds overly complicated.
I need this functionality because I am working on project that is heavily based upon this package:
I am building a django app that allows e.g. journalists to build bots (using the admin interface) without having to code, to be able to use telegram bots as a publishing channel for their content. This might almost sound like a standard telegram channel, but the difference is, that subscribers can set personal preferences on how deep they want to dig into a certain topic, how often they want to receive articles and at which time of the day (which is implemented with django-celery beat). This allows for a more immersive experience of journalistic content, at least that is the idea.
I will keep on trying to solve this issue and of course publish any results. Once I get all of this working, I might also add an example bot builder application to the examples repository, I guess that would be an interesting piece of code to look at.
I have a feeling that this whole project is much harder than I expected, so any help is appreciated ;-)
I don't know if you have noticed telegram has new bot future called Web Apps https://core.telegram.org/bots/webapps
Please consider it on this package.
Hi, I keep on getting:
Exception Value: | 'NoneType' object has no attribute 'get_id' |
---|
Thank you for your api, like django it is fast developing.
My question is how it is possible to forward a message to a channel by bot and then immediately reply to that message.
i know when you forward a message, telegram replies with a response but i cant get that response so that i can reply to forwarded message.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.