diff --git a/django_code/apps/telegram_communication/__init__.py b/django_code/apps/telegram_communication/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/telegram_communication/admin.py b/django_code/apps/telegram_communication/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django_code/apps/telegram_communication/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django_code/apps/telegram_communication/apps.py b/django_code/apps/telegram_communication/apps.py new file mode 100644 index 0000000..8d6cb75 --- /dev/null +++ b/django_code/apps/telegram_communication/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TelegramCommunicationConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'telegram_communication' diff --git a/django_code/apps/telegram_communication/migrations/__init__.py b/django_code/apps/telegram_communication/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/telegram_communication/models.py b/django_code/apps/telegram_communication/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/django_code/apps/telegram_communication/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/django_code/apps/telegram_communication/tests.py b/django_code/apps/telegram_communication/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django_code/apps/telegram_communication/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django_code/apps/telegram_communication/utils.py b/django_code/apps/telegram_communication/utils.py index e69de29..cfc114d 100644 --- a/django_code/apps/telegram_communication/utils.py +++ b/django_code/apps/telegram_communication/utils.py @@ -0,0 +1,39 @@ +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") \ No newline at end of file diff --git a/django_code/apps/telegram_communication/views.py b/django_code/apps/telegram_communication/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/django_code/apps/telegram_communication/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.