From bb39aab3d0d7b249b2acbdb8daec5afd4bee5229 Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Tue, 11 Jan 2022 19:33:18 -0600 Subject: [PATCH] Add basic telegram sending to myself. --- api1.py | 40 +++++++++++++++++++++++++++++++++++++++- session.session | Bin 28672 -> 28672 bytes telegramtest.py | 12 ++++-------- telegramtest2.py | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 telegramtest2.py diff --git a/api1.py b/api1.py index 007e1ae..3193569 100644 --- a/api1.py +++ b/api1.py @@ -5,6 +5,7 @@ from flask_apscheduler import APScheduler from datetime import datetime,timedelta,timezone import sqlite3 import smtplib +from telethon.sync import TelegramClient # testing: # start dummy web server for dev with root: python3 -m smtpd -c DebuggingServer -n localhost:25 @@ -25,6 +26,43 @@ class Config(object): SCHEDULER_API_ENABLED = True +def sendSelfTelegram(text): + print(f"sending telegram message to myself") + # get your api_id, api_hash, token + # from telegram as described above + api_id = '2452309' + api_hash = '4cc6a58946508e59547d15d530a421ae' + + # your phone number + phone = '+13616553044' + + # creating a telegram session and assigning + # it to a variable client + client = TelegramClient('session', api_id, api_hash) + + # connecting and building the session + client.connect() + + # in case of script ran first time it will + # ask either to input token or otp sent to + # number or sent or your telegram id + if not client.is_user_authorized(): + client.send_code_request(phone) + + # signing in the client + client.sign_in(phone, input('Enter the code: ')) + try: + schlingelId=5070349790 + client.send_message(schlingelId, "test message", parse_mode='html') + except Exception as e: + # there may be many error coming in while like peer + # error, wwrong access_hash, flood_error, etc + print(e); + + # disconnecting the telegram session + client.disconnect() + + def sendMail(topic,toAddr): print(f"sending mail to {toAddr} for topic {topic}") port = 25 @@ -32,9 +70,9 @@ def sendMail(topic,toAddr): sender_email = "deadswitch@kawomi.com" receiver_email = toAddr message = f"""Subject: deadSwitch not pushed on topic {topic}\n\nNotification of deadSwitch not pushed on topic {topic}.""" + sendSelfTelegram(message) server.sendmail(sender_email, receiver_email, message) - def expiryCheck(): print('.',end='') db=sqlite3.connect(DATABASE,detect_types=sqlite3.PARSE_DECLTYPES) diff --git a/session.session b/session.session index 2343c328e3c66a91fe7cf8fd33b890e84e8b1495..5cbde987b824a96d55b0eea49b76921add555a5f 100644 GIT binary patch delta 88 zcmV-e0H^bY*g3-X`gj%s(&$VcsP`qChb8RUM-M delta 43 zcmV+`0M!40-~oW(0gxL37Lgo70T!`fq%Q^m56l1$%(D>?!Vi