Answer the question
In order to leave comments, you need to log in
How to make dialogue chains in Telegram Bot?
I'm using pyTelegramBot and I don't need to make chained dialogs.
I found one way, but when using it, an error occurs:
2019-01-13 19:29:22,752 (util.py:64 WorkerThread2) ERROR - TeleBot: "TypeError occurred, args=("'NoneType' object is not callable",)
Traceback (most recent call last):
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\telebot\util.py", line 58, in run
task(*args, **kwargs)
TypeError: 'NoneType' object is not callable
"
Traceback (most recent call last):
File "C:\Users\Rizvan\Desktop\Telegram Bot\bot.py", line 93, in <module>
bot.polling(none_stop=True)
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\telebot\__init__.py", line 264, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\telebot\__init__.py", line 288, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\telebot\util.py", line 107, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Users\Rizvan\Desktop\Telegram Bot\venvbot\lib\site-packages\telebot\util.py", line 58, in run
task(*args, **kwargs)
TypeError: 'NoneType' object is not callable
[Finished in 11.6s]
import telebot
from telebot import types
import json
from models import *
token = 'мой токен'
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(one_time_keyboard=True)
markup.row('Сформировать заказ')
msg = bot.send_message(message.chat.id,'Выберите вариант',reply_markup=markup)
bot.register_next_step_handler(msg, user_enter)
@bot.message_handler(regexp='сформировать заказ')
def user_enter(message):
if message.text.lower() == 'сформировать заказ':
catalog = session.query(Catalog).all()
markup = types.ReplyKeyboardMarkup()
for product in catalog:
markup.row(product.name)
msg = bot.send_message(message.chat.id,'Выберите товар', reply_markup=markup)
bot.register_next_step_handler(msg, user_choice)
def user_choice(message):
catalog = session.query(Catalog).all()
markup = types.ReplyKeyboardMarkup()
for product in catalog:
if product.name == message.text :
msg = bot.send_message(message.chat.id, 'Введите количество')
bot.register_next_step_handler(msg,product_count(message=message,product=product))
def product_count(message, product):
count = message.text
msg = bot.send_message(message.chat.id, 'Товар добавлен в корзину , вы можете продолжить покупки или сделать заказ')
bot.register_next_step_handler(msg, add_to_basket(message,product,count))
def add_to_basket(message,product,count):
prod = Basket(message.from_user.id)
prod.prods.append(product)
session.add(prod)
session.commit()
user_enter(message)
if __name__ == '__main__':
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
I’ll immediately send a link to my template for my bots, there is an answer, but I’ll explain it even
lower Github
. - you call this connection when calling the bot.polling() function), you need to import the apihelper module and make a connection through a proxy server (I used the method with SOCKS proxies, they can be found for free in the cart itself, there are bots that give out, google .) and then everything will work. Now the bot simply cannot connect to the telegram server, which is why an error pops up.
The code for apihelper itself:
from telebot import apihelper
apihelper.proxy = {'http':'http://10.10.1.10:3128'}
#или вариант с socks5
apihelper.proxy = {'https':'socks5://userproxy:[email protected]_address:port'}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question