-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator_cli.py
More file actions
executable file
·59 lines (46 loc) · 1.46 KB
/
Copy pathoperator_cli.py
File metadata and controls
executable file
·59 lines (46 loc) · 1.46 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
#!/usr/bin/env python3
import os
import sys
import requests
from dotenv import load_dotenv
def telegram_request(method, payload=None):
load_dotenv()
token = os.environ.get("TELEGRAM_BOT_TOKEN")
chat_id = os.environ.get("TELEGRAM_CHAT_ID")
if not token or not chat_id:
print("Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID in .env")
return 1
url = f"https://api.telegram.org/bot{token}/{method}"
response = requests.post(url, json=payload or {}, timeout=20)
data = response.json()
if not data.get("ok"):
print(f"Telegram error: {data}")
return 1
return 0
def send_operator_on():
message = (
"Operator is on.\n\n"
"Send completed tasks like:\n"
"completed affidavit of service +\n\n"
"I will log them when the Life OS bot is running."
)
return telegram_request("sendMessage", {
"chat_id": os.environ["TELEGRAM_CHAT_ID"],
"text": message,
})
def status():
code = telegram_request("getMe")
if code == 0:
print("Telegram credentials are valid. If messages are not replying, start the bot.")
return code
def main():
command = (sys.argv[1] if len(sys.argv) > 1 else "on").lower()
if command == "on":
raise SystemExit(send_operator_on())
if command == "status":
raise SystemExit(status())
print("Use: operator on")
print(" operator status")
raise SystemExit(2)
if __name__ == "__main__":
main()