initial telegram sending test
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "C:\\Users\\Joe\\AppData\\Local\\Programs\\Python\\Python39\\python.exe"
|
||||||
|
}
|
||||||
BIN
__pycache__/api1.cpython-37.pyc
Normal file
BIN
__pycache__/api1.cpython-37.pyc
Normal file
Binary file not shown.
BIN
deadswitch.sqlite3
Normal file
BIN
deadswitch.sqlite3
Normal file
Binary file not shown.
3
mail.py
3
mail.py
@@ -1,5 +1,8 @@
|
|||||||
import smtplib
|
import smtplib
|
||||||
|
|
||||||
|
# testing:
|
||||||
|
# start dummy web server for dev with root: python3 -m smtpd -c DebuggingServer -n localhost:25
|
||||||
|
|
||||||
port = 25
|
port = 25
|
||||||
server=smtplib.SMTP("localhost", port)
|
server=smtplib.SMTP("localhost", port)
|
||||||
sender_email = "deadswitch@kawomi.com"
|
sender_email = "deadswitch@kawomi.com"
|
||||||
|
|||||||
BIN
session.session
Normal file
BIN
session.session
Normal file
Binary file not shown.
57
telegramtest.py
Normal file
57
telegramtest.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import telebot
|
||||||
|
from telethon.sync import TelegramClient
|
||||||
|
from telethon.tl.types import InputPeerUser, InputPeerChannel
|
||||||
|
from telethon import TelegramClient, sync, events
|
||||||
|
|
||||||
|
# https://www.geeksforgeeks.org/send-message-to-telegram-user-using-python/
|
||||||
|
|
||||||
|
|
||||||
|
# get your api_id, api_hash, token
|
||||||
|
# from telegram as described above
|
||||||
|
api_id = '2452309'
|
||||||
|
api_hash = '4cc6a58946508e59547d15d530a421ae'
|
||||||
|
token = 'bot token'
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
# 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("B ")
|
||||||
|
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
|
||||||
|
# error, wwrong access_hash, flood_error, etc
|
||||||
|
print(e);
|
||||||
|
|
||||||
|
# disconnecting the telegram session
|
||||||
|
client.disconnect()
|
||||||
Reference in New Issue
Block a user