just add a testing loop to clean messages, will be deleted after testing
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
@@ -2,38 +2,72 @@ import os
|
||||
import requests
|
||||
from apps.bitwarden.utils import bitwardenUtils
|
||||
|
||||
token_uid = "a88dbe52-b862-422a-a116-b479009733ab"
|
||||
chat_id_uid = "13e948ab-494a-4b09-bb3a-b47900974cef"
|
||||
|
||||
__bitwarden_access_token = os.environ.get('bitwarden_access_token')
|
||||
__bitwarden_organization_id = os.environ.get('bitwarden_organization_id')
|
||||
class telegramUtils():
|
||||
|
||||
bw = bitwardenUtils(__bitwarden_access_token,__bitwarden_organization_id)
|
||||
|
||||
__TOKEN = bw.read_value_secret(token_uid)
|
||||
__CHAT_ID = bw.read_value_secret(chat_id_uid)
|
||||
|
||||
|
||||
|
||||
def get_chat_id():
|
||||
# Source - https://stackoverflow.com/a/75118239
|
||||
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
|
||||
# Retrieved 2026-06-30, License - CC BY-SA 4.0
|
||||
|
||||
url = f"https://api.telegram.org/bot{__TOKEN}/getUpdates"
|
||||
print(requests.get(url).json())
|
||||
return 0
|
||||
|
||||
def send_message(message):
|
||||
# Source - https://stackoverflow.com/a/75118239
|
||||
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
|
||||
# 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}"
|
||||
#print(requests.get(url).json()) # this sends the message
|
||||
token_uid = "a88dbe52-b862-422a-a116-b479009733ab"
|
||||
chat_id_uid = "13e948ab-494a-4b09-bb3a-b47900974cef"
|
||||
|
||||
result = requests.get(url).json() # this sends the message
|
||||
send_result = result['ok']
|
||||
return send_result
|
||||
__bitwarden_access_token = os.environ.get('bitwarden_access_token')
|
||||
__bitwarden_organization_id = os.environ.get('bitwarden_organization_id')
|
||||
|
||||
bw = bitwardenUtils(__bitwarden_access_token,__bitwarden_organization_id)
|
||||
|
||||
__TOKEN = bw.read_value_secret(token_uid)
|
||||
__CHAT_ID = bw.read_value_secret(chat_id_uid)
|
||||
|
||||
|
||||
|
||||
def get_chat_id(self):
|
||||
# Source - https://stackoverflow.com/a/75118239
|
||||
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
|
||||
# Retrieved 2026-06-30, License - CC BY-SA 4.0
|
||||
|
||||
url = f"https://api.telegram.org/bot{self.__TOKEN}/getUpdates"
|
||||
print(requests.get(url).json())
|
||||
return 0
|
||||
|
||||
def send_message(self,message):
|
||||
# Source - https://stackoverflow.com/a/75118239
|
||||
# Posted by Yasantha Biyuranga, modified by community. See post 'Timeline' for change history
|
||||
# Retrieved 2026-06-30, License - CC BY-SA 4.0
|
||||
|
||||
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
|
||||
|
||||
result = requests.get(url).json() # this sends the message
|
||||
send_result = result['ok']
|
||||
return send_result
|
||||
|
||||
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
|
||||
|
||||
send_message("Hello")
|
||||
|
||||
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))
|
||||
Reference in New Issue
Block a user