Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send order purchase messages to telegram #473

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions boxoffice/messageclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import requests

from . import app, rq


@rq.job('boxoffice')
def send_telegram_message(order):
with app.test_request_context():
message_text = f'{order.buyer_fullname} purchased {order.line_item.item.title}'
djamg marked this conversation as resolved.
Show resolved Hide resolved
send_text = f'https://api.telegram.org/bot{app.config["TELEGRAM_BOT_TOKEN"]}/sendMessage'
params = {'chat_id': app.config["TELEGRAM_CHAT_ID"], 'text': message_text}
djamg marked this conversation as resolved.
Show resolved Hide resolved
djamg marked this conversation as resolved.
Show resolved Hide resolved
requests.post(send_text, data=params, timeout=30)
2 changes: 2 additions & 0 deletions boxoffice/views/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
send_order_refund_mail,
send_receipt_mail,
)
from ..messageclient import send_telegram_message
from ..models import (
CURRENCY,
CURRENCY_SYMBOL,
Expand Down Expand Up @@ -438,6 +439,7 @@ def payment(order):
invoice_no=order.invoice_no,
),
)
send_telegram_message.queue(order=order)
djamg marked this conversation as resolved.
Show resolved Hide resolved
return api_success(
result={'invoice_id': invoice.id},
doc=_("Payment verified"),
Expand Down
2 changes: 2 additions & 0 deletions instance/settings-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@
#: RQ settings
RQ_REDIS_URL = 'redis://localhost:6379/0'
RQ_SCHEDULER_INTERVAL = 1
TELEGRAM_BOT_TOKEN = ''
TELEGRAM_CHAT_ID = ''