I\'m using Telethon\'s send_message function to send messages to various chats.
Sometimes, the destination is another user (just a regular one on one chat), sometime
I suggest reading this section of the document (entities)
for example, I want to send the message to a user with the username: alix
client = TelegramClient('session_name',
api_id,
api_hash,
)
client.start()
destination_user_username='alix'
entity=client.get_entity(destination_user_username)
client.send_message(entity=entity,message="Hi")
or I want to send the message to a channel with username: test_ali3
client = TelegramClient('session_name',
api_id,
api_hash
)
client.start()
destination_channel_username='test_ali3'
entity=client.get_entity(destination_channel_username)
client.send_message(entity=entity,message="Hi")
or I want to send the message to a group with invite_link: https://t.me/joinchat/Bn4WIhMF1T_ZAF-yM6WbHw
client = TelegramClient('session_name',
api_id,
api_hash
)
client.start()
destination_group_invite_link='https://t.me/joinchat/Bn4WIhMF1T_ZAF-yM6WbHw'
entity=client.get_entity(destination_group_invite_link)
client.send_message(entity=entity,message="Hi")
I hope to be useful to you.