Skip to content

Instantly share code, notes, and snippets.

@amirulabu
Created July 4, 2023 05:26
Show Gist options
  • Save amirulabu/13025a41b74f5b66155c4aa4c68883fe to your computer and use it in GitHub Desktop.
Save amirulabu/13025a41b74f5b66155c4aa4c68883fe to your computer and use it in GitHub Desktop.
python3.9 compatible send message to telegram script
#!/usr/bin/python3
#!/usr/bin/python3
import http.client, json, sys
conn = http.client.HTTPSConnection("api.telegram.org")
body = {'chat_id': xxx, 'text': " ".join(sys.argv[1:]) }
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8')
headers = {"Content-type": "application/json"}
conn.request("POST",
"/botxxxxxxxxxxxaddyourtelegrambottokenherexxxx/sendMessage",
jsondataasbytes, headers)
r1 = conn.getresponse()
print(r1.status, r1.reason)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment