# importing all required librariesimporttelebotfromtelethon.syncimportTelegramClientfromtelethon.tl.typesimportInputPeerUser,InputPeerChannelfromtelethonimportTelegramClient,sync,events# get your api_id, api_hash, token# from telegram as described aboveapi_id='API_id'api_hash='API_hash'token='bot token'message="Working..."# your phone numberphone='YOUR_PHONE_NUMBER_WTH_COUNTRY_CODE'# creating a telegram session and assigning# it to a variable clientclient=TelegramClient('session',api_id,api_hash)# connecting and building the sessionclient.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 idifnotclient.is_user_authorized():client.send_code_request(phone)# signing in the clientclient.sign_in(phone,input('Enter the code: '))try:# receiver user_id and access_hash, use# my user_id and access_hash for referencereceiver=InputPeerUser('user_id','user_hash')# sending message using telegram clientclient.send_message(receiver,message,parse_mode='html')exceptExceptionase:# there may be many error coming in while like peer# error, wrong access_hash, flood_error, etcprint(e);# disconnecting the telegram sessionclient.disconnect()