Skip to content

Commit 1b2475e

Browse files
authored
Merge pull request #208 from Namyalg/Automate-Telegram
Automate Telegram #160
2 parents 70eb5a8 + 30dc05c commit 1b2475e

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

Python/Automate-Telegram/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Automate Telegram ##
2+
- This script can be used to automate the process of sending messages in Telegram
3+
- Here the process of automation is achieved by using the framework Selenium.
4+
- Selenium is a portable framework for testing and automating web applications web applications
5+
6+
## Requirements
7+
- pip install selenium
8+
- pip install web_driver
9+
10+
## Working ##
11+
12+
![Image](assets/login.png)
13+
14+
- The user is prompted to login and verify the phone number
15+
16+
- The user will receive a code which has to be entered
17+
18+
![Image](assets/code.png)
19+
20+
- After the verification process, the user can send messages to the contacts
21+
22+
![Image](assets/send.png)
23+
24+
- The user can send multiple messages to the same user
25+
26+
- The user can also send messages to multiple users
27+
12.1 KB
Loading
10.2 KB
Loading
16.4 KB
Loading
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#Imports and dependencies
2+
from selenium import webdriver
3+
import time
4+
from selenium.webdriver.common.keys import Keys
5+
from webdriver_manager.chrome import ChromeDriverManager
6+
7+
time_wait_thirty = 30
8+
time_wait_four = 4
9+
10+
#Here the process of automation is achieved by using the framework Selenium.
11+
#Selenium is a portable framework for testing and automating web applications web applications
12+
13+
def automate_telegram():
14+
#Path to the chromedriver must be entered without quotations
15+
#Initiating and setting up the driver
16+
driver = webdriver.Chrome(ChromeDriverManager().install())
17+
#For logging into web telegram, the user must verify the phone number
18+
URL = "https://web.telegram.org/#/login"
19+
driver.get(URL)
20+
time.sleep(time_wait_thirty)
21+
user = 1
22+
while user:
23+
driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/div/input").click()
24+
name = input("Enter the name of the person ")
25+
driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/div/input").send_keys(name)
26+
time.sleep(time_wait_four)
27+
driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div[2]/div/div[1]/ul/li").click()
28+
msg = 1
29+
while msg:
30+
message = input("Enter message ")
31+
driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/div/div/form/div[2]/div[5]").send_keys(message)
32+
driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/div/div/form/div[2]/div[5]").send_keys(Keys.ENTER)
33+
print("Do you want to send another message? ")
34+
msg = int(input("Enter 1 to continue, 0 to stop "))
35+
if msg == 0:
36+
break
37+
38+
print("Do you want to send messages to another contact? ")
39+
user = int(input("Enter 1 to continue, 0 to stop "))
40+
41+
return("All messages sent")
42+
43+
if __name__ == "__main__":
44+
automate_telegram()
45+

0 commit comments

Comments
 (0)