Как вызвать функцию python с аннотациями?
У меня есть функция в другом аннотированном методе и есть проблема. Я вызываю ее через django и получаю всевозможные ошибки. вот так.
views.py: `
def callbot():
bot_activate = bot.Command.callBot()
return render(request, bot_activate)
def output(request, temlate_name='custom_change_form.html',):
callbot()
print('work')
return render(request, temlate_name)
**bot.py**
@logerrors
def do_echo(update: Update, context: CallbackContext,):
print('HELLOOOOO')
chat_id = update.message.chat.id
text = update.message.text
p, _ = Profile.objects.get_or_create(
external_id=chat_id,
defaults={
'name': update.message.from_user.username,
}
)
MessagePanel(
profile=p,
text=text,
).save()
reply_text = f"Your ID: {chat_id} \n{text} \n "
update.message.reply_text(text=reply_text,)
@logerrors
def send_text(update: Update, context: CallbackContext,):
chat_id = update.message.chat_id
text = update.message.text
commandname = CommandsForButtons.objects.filter(is_active=True)
print('Its worked')
for mess in commandname:
mess_send = mess.command_text
update.message.reply_text(text=f'It\'s test message: {mess_send}')
do_echo(update, context)
@logerrors
def send_hand_message(update: Update, context: CallbackContext,):
chat_id = update.message.chat_id
text = update.message.text
hand_message = HandMadeMessage.objects.all()
update.message.reply_text(text=f'It\'s test message: {hand_message}')
class Command(BaseCommand):
help = 'Telegram-Bot'
def handle(self, *args, **options):
hand_message = HandMadeMessage.objects.all()
request = Request(
connect_timeout=0.5,
read_timeout=1.0,
)
bot = Bot(
request=request,
token=settings.TOKEN,
base_url=getattr(settings, 'PROXY_URL', None),
)
to_bot_panel, _ = BotsPanel.objects.get_or_create(
bot_id = bot.get_me().id,
bot_name = bot.get_me().first_name,
bot_nickname= bot.get_me().username,
bot_token= bot.token
)
print(bot.get_me())
updater = Updater(
bot=bot,
use_context=True,
)
#Commands
def callBot():
return send_text(Update, CallbackContext)
updater.dispatcher.add_handler(CommandHandler('get', send_text,))
updater.dispatcher.add_handler(MessageHandler(Filters.text, do_echo))
updater.start_polling()
updater.idle()
` Может вы знаете, что мне делать?) Я не знаю как решить эту проблему, и я не прошу вас писать код, если у кого-то есть возможность объяснить, то я прошу вас, сделайте это хаха)))
chat_id = update.message.chat_id
Разве это не должно быть
chat_id = update.message.chat.id
?
В вашем примере в первой функции вы используете chat.id
, затем в следующих методах вы используете chat_id
.