Модульный Telegram-бот с возможностью редактирования прав доступа, как пользователям, так и группам пользователей
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.
 
 

28 lines
1.0 KiB

from django.contrib import messages
from django.http import HttpResponseRedirect
from django.shortcuts import render, HttpResponse
import requests
from django.urls import reverse
from adminpanel.models import Orders
from bot_sys.config import g_telegram_bot_api_token
def send_telegram_message(request, chat_id):
if request.method == 'POST':
message = request.POST.get('message')
bot_token = g_telegram_bot_api_token
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')