we can send messages through telegram now

This commit is contained in:
2026-06-30 10:12:44 +01:00
parent b11c840688
commit 5478a1032c
8 changed files with 57 additions and 0 deletions
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class TelegramCommunicationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'telegram_communication'
@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
@@ -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")
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.