-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytelegram.py
48 lines (40 loc) · 1.62 KB
/
mytelegram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# importing all required libraries
import telebot
from telethon.sync import TelegramClient
from telethon.tl.types import InputPeerUser, InputPeerChannel
from telethon import TelegramClient, sync, events
from param import *
class bot():
def __init__(self,id):
# get your api_id, api_hash, token
# from telegram as described above
self.api_id = api_id
self.api_hash = api_hash
self.message = "Working..."
# your phone number
self.phone = phone
# creating a telegram session and assigning
# it to a variable client
self.client = TelegramClient(id, self.api_id, self.api_hash)
# connecting and building the session
self.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 self.client.is_user_authorized():
self.client.send_code_request(self.phone)
# signing in the client
self.client.sign_in(self.phone, input('Enter the code: '))
def send(self, mess):
try:
# receiver user_id and access_hash, use
# my user_id and access_hash for reference
#self.client.send_message(num1,mess)
#self.client.send_message(num2,mess)
self.client.send_message(num3,mess)
except Exception as e:
# there may be many error coming in while like peer
# error, wrong access_hash, flood_error, etc
print(e)
# disconnecting the telegram session
#client.disconnect()