xxxxxxxxxx
# pip install python-telegram-bot --upgrade
import logging
from telegram import ForceReply, Update
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
# Define a few command handlers. These usually take the two arguments update and
# context.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /start is issued."""
user = update.effective_user
await update.message.reply_html(
rf"Hi {user.mention_html()}!",
reply_markup=ForceReply(selective=True),
)
xxxxxxxxxx
import requests
def send_msg(text):
token = "your_token"
chat_id = "your_chatId"
url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text
results = requests.get(url_req)
print(results.json())
send_msg("Hello there!")
send message telegram python
xxxxxxxxxx
import requests
def send_msg(text):
token = "your_token"
chat_id = "your_chatId"
url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text
results = requests.get(url_req)
print(results.json())
send_msg("Hello there!")
xxxxxxxxxx
import telegram
bot_token = 'YOUR_BOT_TOKEN'
chat_id = 'CHAT_ID_OF_THE_RECEIVER'
message_text = 'Hello, World!'
bot = telegram.Bot(token=bot_token)
bot.send_message(chat_id=chat_id, text=message_text)