From 8cb2ffafc70fd30dc20e59caf5edc00cfff0b67b Mon Sep 17 00:00:00 2001 From: RezenkovD Date: Wed, 16 Aug 2023 13:04:12 +0300 Subject: [PATCH 1/3] feat: update example.env --- example.env | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example.env b/example.env index 6739d2e..23ae8c3 100644 --- a/example.env +++ b/example.env @@ -17,3 +17,7 @@ GOOGLE_SECRET='' # EMAIL EMAIL_HOST_USER=host@example.com EMAIL_HOST_PASSWORD='' + +# TELEGRAM BOT +BOOKING_TELEGRAM_API_TOKEN='' +BOOKING_TELEGRAM_CHAT_ID='' \ No newline at end of file From af69284ae77e9a2be09e5c79a67fc41b87cf3146 Mon Sep 17 00:00:00 2001 From: RezenkovD Date: Wed, 16 Aug 2023 13:06:23 +0300 Subject: [PATCH 2/3] feat: add bot for send mess about booking --- vr_club/settings.py | 2 ++ vr_club_site/utils.py | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/vr_club/settings.py b/vr_club/settings.py index 2e49c3d..66822d1 100644 --- a/vr_club/settings.py +++ b/vr_club/settings.py @@ -39,6 +39,8 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") USE_X_FORWARDED_HOST = env("USE_X_FORWARDED_HOST") # Application definition +BOOKING_BOT_TOKEN = env("BOOKING_TELEGRAM_API_TOKEN") +BOOKING_CHAT_ID = env("BOOKING_TELEGRAM_CHAT_ID") INSTALLED_APPS = [ # "whitenoise.runserver_nostatic", diff --git a/vr_club_site/utils.py b/vr_club_site/utils.py index 8311d23..0e57a29 100644 --- a/vr_club_site/utils.py +++ b/vr_club_site/utils.py @@ -1,4 +1,6 @@ import calendar +import requests +import os import decimal from datetime import datetime, date @@ -8,12 +10,19 @@ from django.contrib import messages from .models import Booking, BookingTime, ACTUAL, Settings +from vr_club.settings import BOOKING_BOT_TOKEN, BOOKING_CHAT_ID - -COST_SESSION = 200 MAX_SESSION = 2 +def send_order_details(api_token, chat_id, order_details): + url = f"https://api.telegram.org/bot{api_token}/sendMessage" + message = f"Нове замовлення:\n\n{order_details}" + payload = {"chat_id": chat_id, "text": message} + response = requests.post(url, data=payload) + return response + + def get_price(date): day_of_week = date.weekday() if day_of_week >= 5: @@ -191,5 +200,16 @@ def book_session(request, slots, data_to_save): for booking_time in booking_times_to_create: booking.time.add(booking_time) + + order_details = f"Ім'я: {booking.name}\n" + order_details += f"Email: {booking.email}\n" + order_details += f"Телефон: {booking.phone_number}\n" + order_details += f"Дата: {data_to_save['date']}\n" + order_details += f"Слоти: {slots}\n" + order_details += f"Кількість людей: {booking.people_count}\n" + order_details += f"Ціна: {booking.price} грн\n" + order_details += f"Коментар: {booking.comment}\n" + + send_order_details(BOOKING_BOT_TOKEN, BOOKING_CHAT_ID, order_details) except IntegrityError as e: messages.error(request, f"Помилка бронювання: {e}") From cf15b30bffedc167125e751c722923c1ef1f4578 Mon Sep 17 00:00:00 2001 From: RezenkovD Date: Wed, 16 Aug 2023 13:09:10 +0300 Subject: [PATCH 3/3] feat: update yml file --- .github/workflows/ci_cd.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index d69a77d..4db64f5 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -87,6 +87,8 @@ jobs: GOOGLE_SECRET: ${{ secrets.GOOGLE_SECRET }} CSRF_TRUSTED_ORIGINS: ${{ secrets.CSRF_TRUSTED_ORIGINS }} USE_X_FORWARDED_HOST: ${{ secrets.USE_X_FORWARDED_HOST }} + BOOKING_TELEGRAM_API_TOKEN: ${{ secrets.BOOKING_TELEGRAM_API_TOKEN }} + BOOKING_TELEGRAM_CHAT_ID: ${{ secrets.BOOKING_TELEGRAM_CHAT_ID }} - name: Upload coverage report uses: actions/upload-artifact@v2 @@ -174,6 +176,8 @@ jobs: export SUB_DOMAIN='${{ secrets.SUB_DOMAIN }}' export CSRF_TRUSTED_ORIGINS=${{ secrets.CSRF_TRUSTED_ORIGINS }} export USE_X_FORWARDED_HOST='${{ secrets.USE_X_FORWARDED_HOST }}' + export BOOKING_TELEGRAM_API_TOKEN='${{ secrets.BOOKING_TELEGRAM_API_TOKEN }}' + export BOOKING_TELEGRAM_CHAT_ID='${{ secrets.BOOKING_TELEGRAM_CHAT_ID }}' git pull pip3 install -r requirements.txt @@ -209,6 +213,8 @@ jobs: export SUB_DOMAIN='${{ secrets.SUB_DOMAIN }}' export CSRF_TRUSTED_ORIGINS=${{ secrets.CSRF_TRUSTED_ORIGINS }} export USE_X_FORWARDED_HOST='${{ secrets.USE_X_FORWARDED_HOST }}' + export BOOKING_TELEGRAM_API_TOKEN='${{ secrets.BOOKING_TELEGRAM_API_TOKEN }}' + export BOOKING_TELEGRAM_CHAT_ID='${{ secrets.BOOKING_TELEGRAM_CHAT_ID }}' sudo apt-get install -y libpq-dev python3-dev sudo apt-get install -y build-essential