So in your opinion - I should have it be webhook based if I want it to be running permanently? I'm willing to start at least the lowest tier payment account. You have been so nice and helpful, that alone is convincing enough for me to go back to a paying account and to keep on developing.
Do I need to change the code at all or just delete my console based bot code/file and focus all the code into the webhook/web directory files?
As always, thanks giles.
BIG Edit: I deleted my console based bot files and moved soley to the web directory. I'm still getting a webhook error with getupdates even though I have no consoles open for a console based bot. I also got rid of the free account code with the proxy server or whatever since I have the low tier paid account now. Here is my current code:
from flask import Flask, request
import time
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
secret = "8008"
bot = telepot.Bot('botfather token')
bot.setWebhook("https://guapogi.pythonanywhere.com/{}".format(secret), max_connections=1)
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def telegram_webhook():
update = request.get_json()
if "message" in update:
text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
bot.sendMessage(chat_id, "From the web: you said '{}'".format(text))
return "OK"
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text='Press me', callback_data='press')],
])
bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard)
def on_callback_query(msg):
query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
print('Callback Query:', query_id, from_id, query_data)
bot.answerCallbackQuery(query_id, text='Got it')
TOKEN = "botfather token" #set token to botfather token
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')
while 1:
time.sleep(10)
I thought I needed to add a Flask app to run it on the website or something. Mind you I don't know what I was doing or if this stuff will even work together. facepalm
Big edit #2:
Current code. No errors, but this doesn't even return a message when I talk to the bot anymore:
from flask import Flask, request
import time
import telepot
#from telepot.loop import MessageLoop
#from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
secret = "8008"
bot = telepot.Bot('botfather token')
bot.setWebhook("https://guapogi.pythonanywhere.com/{}".format(secret), max_connections=1)
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def telegram_webhook():
update = request.get_json()
if "message" in update:
text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
bot.sendMessage(chat_id, "From the web: you said '{}'".format(text))
return "OK"
"""
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text='Press me', callback_data='press')],
])
bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard)
def on_callback_query(msg):
query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
print('Callback Query:', query_id, from_id, query_data)
bot.answerCallbackQuery(query_id, text='Got it')
TOKEN = "botfather token" #set token to botfather token
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
'callback_query': on_callback_query}).run_as_thread()
"""
print('Listening ...')
while 1:
time.sleep(10)
Apologies for being such a bother. Just want it to work lol