|
| 1 | +from twilio.rest import Client |
| 2 | +from telethon import TelegramClient |
| 3 | +import requests |
| 4 | +from telethon.tl.types import InputPeerChat |
| 5 | +from telethon.tl.functions.messages import ImportChatInviteRequest |
| 6 | + |
| 7 | +# Define your API credentials |
| 8 | +api_id = ##### |
| 9 | +api_hash = '######################' |
| 10 | + |
| 11 | +# Twilio API credentials |
| 12 | +account_sid = '###############' |
| 13 | +auth_token = '################' |
| 14 | +twilio_client = Client(account_sid, auth_token) |
| 15 | + |
| 16 | +# Telegram API client setup |
| 17 | +telegram_client = TelegramClient('session_name', api_id, api_hash) |
| 18 | +telegram_client.start() |
| 19 | + |
| 20 | +def send_telegram_message(chat_id, message): |
| 21 | + chat = InputPeerChat(chat_id) |
| 22 | + telegram_client.send_message(chat, message) |
| 23 | + |
| 24 | +def send_twilio_sms(to_phone_number, message): |
| 25 | + twilio_client.messages.create(to=to_phone_number, from_='##########', body=message) |
| 26 | + |
| 27 | +def make_twilio_call(to_phone_number): |
| 28 | + twilio_client.calls.create(url='http://demo.twilio.com/docs/voice.xml', to=to_phone_number, from_='#############') |
| 29 | + |
| 30 | +def check_sites(site_list, chat_id): |
| 31 | + for site in site_list: |
| 32 | + print(site) |
| 33 | + r = requests.head(site) |
| 34 | + if r.status_code == 200: |
| 35 | + message = site + " returned 200" |
| 36 | + send_telegram_message(chat_id, message) |
| 37 | + sms_message = "The " + site + " is not responding now" |
| 38 | + send_twilio_sms("#####", sms_message) |
| 39 | + make_twilio_call('############') |
| 40 | + else: |
| 41 | + message = "Oops " + site + " not available at the moment" |
| 42 | + send_telegram_message(chat_id, message) |
| 43 | + |
| 44 | +if __name__ == '__main__': |
| 45 | + # Define the site list and chat ID here |
| 46 | + site_list = ['http://example.com', 'http://example2.com'] |
| 47 | + chat_id = 123456789 # Replace with the actual chat ID |
| 48 | + check_sites(site_list, chat_id) |
0 commit comments