39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
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')
|
|
|
|
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
|
|
|
|
result = requests.get(url).json() # this sends the message
|
|
send_result = result['ok']
|
|
return send_result
|
|
|
|
send_message("Hello") |