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 2343c32..5cbde98 100644 Binary files a/session.session and b/session.session differ diff --git a/telegramtest.py b/telegramtest.py index 8d07e69..f4b46c7 100644 --- a/telegramtest.py +++ b/telegramtest.py @@ -1,4 +1,3 @@ -import telebot from telethon.sync import TelegramClient from telethon.tl.types import InputPeerUser, InputPeerChannel from telethon import TelegramClient, sync, events @@ -36,17 +35,14 @@ if not client.is_user_authorized(): try: # receiver user_id and access_hash, use # my user_id and access_hash for reference - print(client.get_me().stringify()) - print("A") - #receiver = InputPeerUser('user_id', 'user_hash') - receiver = InputPeerUser('1463709677', '4835783730631176464') + #print(client.get_me().stringify()) + # send message to self... + receiver = InputPeerUser( str(client.get_me().id), str(client.get_me().access_hash)) - print("B ") - print(receiver) + #print(receiver) # sending message using telegram client #client.send_message(receiver, message, parse_mode='html') client.send_message(1463709677, "test message", parse_mode='html') - print("C") except Exception as e: # there may be many error coming in while like peer diff --git a/telegramtest2.py b/telegramtest2.py new file mode 100644 index 0000000..f35804b --- /dev/null +++ b/telegramtest2.py @@ -0,0 +1,35 @@ +from telethon.sync import TelegramClient + +# 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()