Answer the question
In order to leave comments, you need to log in
How to send a Telegram message to a bot (in python), after running a successful ping command?
I am learning python and making a simple telegram bot. Essence of the question: when the ping command is successfully executed, which is launched on my PC using python (sends 4 packets), a notification should come to the telegram bot. How can this be written? Something like the code below, only now it writes to me when I press the start button, I would like it to be just a message.
import telnetlib
import os
import telebot
host = "hostname"
ping = os.system("ping -c 1 " + host)
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(content_types=['text'])
def get_message (message):
if ping == 0:
bot.send_message(message.chat.id, text = "PING")
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question