testing #16

Merged
pi-ux-ce merged 34 commits from testing into main 2026-07-04 17:40:00 +00:00
Showing only changes of commit ec2696ee43 - Show all commits
@@ -2,6 +2,9 @@ import os
import requests import requests
from apps.bitwarden.utils import bitwardenUtils from apps.bitwarden.utils import bitwardenUtils
class telegramUtils():
token_uid = "a88dbe52-b862-422a-a116-b479009733ab" token_uid = "a88dbe52-b862-422a-a116-b479009733ab"
chat_id_uid = "13e948ab-494a-4b09-bb3a-b47900974cef" chat_id_uid = "13e948ab-494a-4b09-bb3a-b47900974cef"
@@ -15,25 +18,56 @@ __CHAT_ID = bw.read_value_secret(chat_id_uid)
def get_chat_id(): def get_chat_id(self):
# Source - https://stackoverflow.com/a/75118239 # Source - https://stackoverflow.com/a/75118239
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history # Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
# Retrieved 2026-06-30, License - CC BY-SA 4.0 # Retrieved 2026-06-30, License - CC BY-SA 4.0
url = f"https://api.telegram.org/bot{__TOKEN}/getUpdates" url = f"https://api.telegram.org/bot{self.__TOKEN}/getUpdates"
print(requests.get(url).json()) print(requests.get(url).json())
return 0 return 0
def send_message(message): def send_message(self,message):
# Source - https://stackoverflow.com/a/75118239 # Source - https://stackoverflow.com/a/75118239
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history # Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
# Retrieved 2026-06-30, License - CC BY-SA 4.0 # Retrieved 2026-06-30, License - CC BY-SA 4.0
url = f"https://api.telegram.org/bot{__TOKEN}/sendMessage?chat_id={__CHAT_ID}&text={message}" url = f"https://api.telegram.org/bot{self.__TOKEN}/sendMessage?chat_id={self.__CHAT_ID}&text={message}"
#print(requests.get(url).json()) # this sends the message #print(requests.get(url).json()) # this sends the message
result = requests.get(url).json() # this sends the message result = requests.get(url).json() # this sends the message
send_result = result['ok'] send_result = result['ok']
return send_result return send_result
send_message("Hello") def send_document(self,file,message=''):
url = 'https://api.telegram.org/bot{}/sendDocument'.format(self.__TOKEN)
data = {'chat_id': self.__CHAT_ID ,'caption': message}
document = open(file, 'rb')
files = {'document': document}
response = requests.post(url, data=data, files=files)
result = response.json()
return result['ok'],result['result']['message_id'],result
#example send_document('apps/Le_journal_10h00_du_30_06_2026.mp3')
def delete_message(self,message_id_list):
send_result = []
for message_id in message_id_list:
url = f"https://api.telegram.org/bot{self.__TOKEN}/deleteMessage?chat_id={self.__CHAT_ID}&message_id={message_id}"
result = requests.get(url).json()
send_result.append(["Message id: "+str(message_id),result['ok']])
return send_result,result
telegram = telegramUtils()
#send_message("Hello")
print(telegram.send_document('apps/Le_journal_10h00_du_30_06_2026.txt',"News du jour 2"))
#print(telegram.send_document('apps/Le_journal_10h00_du_30_06_2026.txt'))
#just delete everything , for testing
list_message_to_delete = []
for i in range(26):
list_message_to_delete.append(i)
print(telegram.delete_message(list_message_to_delete))