Skip to content

Instantly share code, notes, and snippets.

@sansal54
Created September 11, 2019 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansal54/8e1ad4073e5c2fd3e92ecaf0d8ac26b2 to your computer and use it in GitHub Desktop.
Save sansal54/8e1ad4073e5c2fd3e92ecaf0d8ac26b2 to your computer and use it in GitHub Desktop.
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