-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTelegram_Message.py
More file actions
77 lines (55 loc) · 2.63 KB
/
Copy pathTelegram_Message.py
File metadata and controls
77 lines (55 loc) · 2.63 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 21 01:13:23 2022
Here i coded how to send a message/file to telegram user/group using python
Contact details :
Telegram Channel: https://t.me/pythontrader
Developer Telegram ID : https://t.me/pythontrader_admin
Gmail ID: mnkumar2020@gmail.com
Whatsapp : 9470669031
Disclaimer: The information provided by the Python Traders channel is for educational purposes only, so please contact your financial adviser before placing your trade. Developer is not responsible for any profit/loss happened due to coding, logical or any type of error.
"""
#link to get user id/ group id or any activity related to our bot
#https://api.telegram.org/bot5747611163:AAFqIPOxRGTXP25py8mNdXRL7mz-TfsouO8/getUpdates
import requests
#please generate your bot and update TelegramBotCredential and ReceiverTelegramID below :
#TelegramBotCredential = '5747611163:AAFqIPOxRGTXP25py8mNdXRL7mz-TfsouO8'
#ReceiverTelegramID = '5242432731' #my personal id
#TelegramBotCredential = '69741111df1efdb5f25f6afd5eb0e098'
TelegramBotCredential = '6106136909:AAEWKu4Xk1QtoIjMnoZzblRdc5SZdcntOTY'
ReceiverTelegramID='5416986599'
def SendMessageToTelegram(Message):
try:
Url = "https://api.telegram.org/bot" + str(TelegramBotCredential) + "/sendMessage?chat_id=" + str(ReceiverTelegramID)+"&text=HIHello"
#textdata ={ "text":Message}
response = requests.request("POST",Url)
print(response)
except Exception as e:
Message = str(e) + ": Exception occur in SendMessageToTelegram"
print(Message)
import telegram
def send_mess(text):
#token = "XXXXXX"
#chat_id = "XXXXXX"
try:
bot = telegram.Bot(token=TelegramBotCredential)
bot.sendMessage(chat_id=ReceiverTelegramID, text=text)
print("Done")
except Exception as e:
Message = str(e) + ": Exception occur in send_mess"
print(Message)
import requests
def send_to_telegram(message):
apiURL = f'https://api.telegram.org/bot{TelegramBotCredential}/sendMessage'
try:
response = requests.post(apiURL, json={'chat_id': ReceiverTelegramID, 'text': message})
print(response.text)
except Exception as e:
print(e)
send_to_telegram("Hello from Python!")
def SendTelegramFile(FileName):
Documentfile={'document':open(FileName,'rb')}
Fileurl = "https://api.telegram.org/bot" + str(TelegramBotCredential) + "/sendDocument?chat_id=" + str(ReceiverTelegramID)
response = requests.request("POST",Fileurl,files=Documentfile)
#send_mess("HiHi")
#SendMessageToTelegram("HI")