Hi!
I am trying to set telegram bot using pyTelegramBotApi (https://github.com/eternnoir/pyTelegramBotAPI). But I am stuck with using decorators. So, my code is like this:
from flask import Flask, request
import telebot
from telebot import types
secret = "c04a4995-a7e2-4bf5-b8ab-d7599105d1d1"
bot = telebot.TeleBot('mytoken')
bot.remove_webhook()
bot.set_webhook(url="https://myusername.pythonanywhere.com/{}".format(secret))
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def lololo():
update = request.get_json()
if "message" in update:
text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
bot.send_message(chat_id, update["message"]["chat"]["first_name"])
return "ok"
@bot.message_handler(commands=['start', 'help'])
def startCommand(update):
bot.send_message(update["message"]["chat"]["id"], 'Test string for /start and /help')
So, this code is only returning me my name despite what I send - whether it is just a message or /start command - response is the same. So how should I use decorator to handle certain commands?
Also I tried code from here (https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/webhook_examples/webhook_flask_echo_bot.py). I copied and pasted the code and replaced all necessary fields with my actual data. But it doen't work either.
Please, could you help me? Any suggestions will be very appreciated. Thanks
P.S. In the meantime I am I am using version of my bot without webhooks. Just Nonstop polling, which I started in the pythonanywhere console. But I am not sure whether it is right to do so