Python Telegram Bot answer
Question:
How can I get response from Telegram bot and get some information to answer from local file? I wrote code below, but part with current_status
doesn’t work.
Could you please tell me why it doesn’t work?
import telebot
import requests
url = "https://link.com"
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
if message.text == "Status" or "status":
bot.send_message(message.from_user.id, curl_request())
def current_status():
with open('current_status.log') as file:
status = str(file.readline())
return status
def curl_request():
resp = requests.get(url)
if resp.status_code == 200:
return("Available n", current_status())
else:
return("Isn't available n", current_status())
bot.polling(none_stop=True, interval=0)
I mean, I getting answer from bot in Telegram just Available
or Isn't available
without text from my file which I open in current_status
function.
Answers:
bot.send_message()
takes text as its second parameter, but your function curl_request()
returns tuple.
Can you try make it return "Available n" + current_status()
?
How can I get response from Telegram bot and get some information to answer from local file? I wrote code below, but part with current_status
doesn’t work.
Could you please tell me why it doesn’t work?
import telebot
import requests
url = "https://link.com"
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
if message.text == "Status" or "status":
bot.send_message(message.from_user.id, curl_request())
def current_status():
with open('current_status.log') as file:
status = str(file.readline())
return status
def curl_request():
resp = requests.get(url)
if resp.status_code == 200:
return("Available n", current_status())
else:
return("Isn't available n", current_status())
bot.polling(none_stop=True, interval=0)
I mean, I getting answer from bot in Telegram just Available
or Isn't available
without text from my file which I open in current_status
function.
bot.send_message()
takes text as its second parameter, but your function curl_request()
returns tuple.
Can you try make it return "Available n" + current_status()
?