You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1000 B
25 lines
1000 B
from django.contrib import messages |
|
from django.http import HttpResponseRedirect |
|
import requests |
|
from django.urls import reverse |
|
from django.shortcuts import render |
|
from bot_sys.config import GetTelegramBotApiToken |
|
|
|
def send_telegram_message(request, chat_id): |
|
if request.method == 'POST': |
|
message = request.POST.get('message') |
|
|
|
bot_token = GetTelegramBotApiToken() |
|
url = f'https://api.telegram.org/bot{bot_token}/sendMessage?text={message}&chat_id={chat_id}' |
|
|
|
response = requests.get(url) |
|
if response.status_code == 200: |
|
messages.success(request, "Сообщение успешно отправлено") |
|
back_url = reverse('') |
|
return HttpResponseRedirect(back_url) |
|
else: |
|
messages.error(request, "Сообщение не отправлено") |
|
back_url = reverse('') |
|
return HttpResponseRedirect(back_url) |
|
else: |
|
return render(request, 'send_telegram_message.html') |