Skip to content

Instantly share code, notes, and snippets.

@FloPinguin
Created December 30, 2021 15:21
Show Gist options
  • Save FloPinguin/d7f0b6a27fbb8b4303e22a25f64dd195 to your computer and use it in GitHub Desktop.
Save FloPinguin/d7f0b6a27fbb8b4303e22a25f64dd195 to your computer and use it in GitHub Desktop.
def send_telegram(msg, log=False):
r = None
try:
token = ""
if log:
token = ""
for start in range(0, len(msg), 4000):
data = {'chat_id': 123456789, 'text': msg[start:start+4000]}
r = requests.post("https://api.telegram.org/bot" + token + "/sendMessage", timeout=30, data=data)
r.raise_for_status()
except Exception as e:
out = ""
if r is not None:
out = " (" + r.text + ")"
print("Could not send telegram message \"" + msg + "\": " + str(e) + out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment