Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send message to Telegram
import urllib.request
# Generate a bot ID here: https://core.telegram.org/bots#botfather
token = "822598813:AAHfVAjmDU3A6AgLpzbMEVImseo6a9HV5qo"
sansal_chat_id = "595115128"
kadir_chat_id = "936825399"
mymessage = "mesaj123"
url = "https://api.telegram.org/bot822598813:AAHfVAjmDU3A6AgLpzbMEVImseo6a9HV5qo/sendMessage?chat_id=595115128&text=Sansal"
# Request latest messages
#result = urllib.request.urlopen("https://api.telegram.org/bot" + token + "/getUpdates").read()
#print(result)
# Send a message to a chat room (chat room ID retrieved from getUpdates)
url = "https://api.telegram.org/bot" + token + "/sendMessage?chat_id=" + sansal_chat_id + "&text=" + mymessage
url2 = "https://api.telegram.org/bot" + token + "/sendMessage?chat_id=" + kadir_chat_id + "&text=" + mymessage
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
print (response.read().decode('utf-8'))
request2 = urllib.request.Request(url2)
response2 = urllib.request.urlopen(request2)
print (response2.read().decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.