Skip to content

Commit

Permalink
purely comments: ToDo & DriverAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
schwabix-1311 committed Feb 26, 2024
1 parent c3bbc47 commit 0ffa2ca
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ToDo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ aquaPi ToDo list
controller: null (out=in), delay
input: schedule analog?, random
aux: min, limiter
misc: email, telegram (pyTelegramBotAPI), history, cloud telemetry, macro
misc: email, telegram, history, cloud telemetry, macro

- macros!?! = scheduled/triggered sender of msgs on the bus? wait for msgs?
This will require affected nodes to supended their listening to avoid conflicts.
Expand Down Expand Up @@ -78,7 +78,31 @@ aquaPi ToDo list
adapter µUSB->USB A plus cable USB A -> USB B

- Telegram bot in Python:
package pyTelegramBotAPI,
https://thepythoncorner.com/posts/2021-01-16-how-create-telegram-bot-in-python/
in channel BotFather /newbot: name aquaPi, bot @UNIQUE_bot, remeber bot token,
find own "chat id": https://web.telegram.org/z/#?tgaddr=tg://resolve?domain=schwabix,
this redirects to a URL ending in your chat id
OR join and start @RawDataBot, it will reply with json showing your chat:id
OR join and start your bot, then https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
send message - 8135... is bot token, 1261... is chat id - multiple subscribers??:
https://api.telegram.org/bot813504918:AAEQ0ec6XT6i0BSvF3ldVrmepETMTjyxNiE/sendMessage?chat_id=126177523&text=bot6135_to_1261..
and modify/update it:
https://api.telegram.org/bot813504918:AAEQ0ec6XT6i0BSvF3ldVrmepETMTjyxNiE/editMessageText?message_id=2983&chat_id=126177523&text=changed_Text
get message history (depth?), could be used to receive commands:
https://api.telegram.org/bot6494591607:AAHH4nCC-vD8clvfiMryls_ZpdJi_HskctM/getUpdates
sample ->
{"ok":true,"result":[{"update_id":23832511,
"message":{"message_id":1,"from":{"id":126177523,"is_bot":false,"first_name":"Markus","username":"schwabix","language_code":"de"},"chat":{"id":126177523,"first_name":"Markus","username":"schwabix","type":"private"},"date":1691342697,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":23832512,
...
"message":{"message_id":7,"from":{"id":126177523,"is_bot":false,"first_name":"Markus","username":"schwabix","language_code":"de"},"chat":{"id":126177523,"first_name":"Markus","username":"schwabix","type":"private"},"date":1691343059,"text":"soso"}},{"update_id":23832516,
"message":{"message_id":10,"from":{"id":126177523,"is_bot":false,"first_name":"Markus","username":"schwabix","language_code":"de"},"chat":{"id":126177523,"first_name":"Markus","username":"schwabix","type":"private"},"date":1691343182,"text":"silence"}}]}

or bot as group member allows multiple receivers, but only 1 bot??:
https://api.telegram.org/bot6494591607:AAHH4nCC-vD8clvfiMryls_ZpdJi_HskctM/sendMessage?chat_id=-978207359&text=ph%20Alarm!

OR simple sample without dedicated package!!:
https://medium.com/codex/using-python-to-send-telegram-messages-in-3-simple-steps-419a8b5e5e2

- packaging and deployment ... long way to there!

Expand Down
31 changes: 31 additions & 0 deletions aquaPi/driver/DriverAlert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Extract from medium.com "using-python-to-send-telegram-messages-in-3-simple-steps"
2. Getting your chat ID
In Telegram, every chat has a chat ID, and we need this chat ID to send Telegram messages using Python.
Send your Telegram bot a message (any random message)
Run this Python script to find your chat ID
import requests
TOKEN = "YOUR TELEGRAM BOT TOKEN"
url = f"https://api.telegram.org/bot{TOKEN}/getUpdates"
print(requests.get(url).json())
This script calls the getUpdates function, which kinda checks for new messages. We can find our chat ID from the returned JSON (the one in red)
Note: if you don’t send your Telegram bot a message, your results might be empty.
3. Copy and paste the chat ID into our next step
3. Sending your Telegram message using Python
Copy and paste 1) your Telegram bot token and 2) your chat ID from the previous 2 steps into the following Python script. (And do customize your message too)
import requests
TOKEN = "YOUR TELEGRAM BOT TOKEN"
chat_id = "YOUR CHAT ID"
message = "hello from your telegram bot"
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"
print(requests.get(url).json()) # this sends the message
"""

0 comments on commit 0ffa2ca

Please sign in to comment.