Autor: n1g1channel 2022-02-10 19:38
pip3 install pyTelegramBotAPI
import telebot # Importamos las librería
import requests
import json
De igual forma necesitamos obtener un token en Telegram, para ello le debemos de dar clic a la lupita en Telegram y posteriormente buscar ¨BotFather¨ sin comillas, y crear un bot, una vez lo tengamos creado nos dará un token.TOKEN = "TU_TOKEN"
def getError():
respuesta = "Algo salió mal con la API"
return respuesta
# Método para dar un error cuando falla
def getBtc():
try:
response = requests.get("https://www.bitstamp.net/api/v2/ticker/btcusd")
response = response.json()
return str("{:,.2f}".format(float(response["last"])))
except:
return getError()
@bot.message_handler(commands=['panas', 'help'])
def send_welcome(message):
try:
mensaje = 'Hola @'+getUsuario(message)+ u', '+'El precio del BTC es de: $' + getBtc()
except:
mensaje = 'Estoy agarrando señal carnal...'
bot.reply_to(message, mensaje)
Video tutorial:
!pip3 install pyTelegramBotAPI
import telebot # Importamos las librería
import requests
import json
TOKEN = "TU_TOKEN"
bot = telebot.TeleBot(TOKEN)
def getError():
respuesta = "Algo salió mal con la API"
return respuesta
def getBtc():
try:
response = requests.get("https://www.bitstamp.net/api/v2/ticker/btcusd")
response = response.json()
return str("{:,.2f}".format(float(response["last"])))
except:
return getError()
@bot.message_handler(commands=['panas'])
def sentMessage(message):
try:
mensaje = 'Hola, '+'El precio del BTC es de: $' + getBtc()
except:
mensaje = 'Estoy agarrando señal carnal...'
bot.reply_to(message, mensaje)
@bot.message_handler(commands=['panas2'])
def sentMessage(message):
try:
mensaje = 'Esta es una prueba'
except:
mensaje = 'Estoy agarrando señal carnal...'
bot.reply_to(message, mensaje)
bot.infinity_polling(timeout=10, long_polling_timeout = 5)
user = bot.get_me()
updates = bot.get_updates()