-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Telegram integration to receive contact message in the bot chat
- Loading branch information
1 parent
a1ffc0d
commit 7605f31
Showing
5 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import requests | ||
from django.conf import settings | ||
|
||
class TelegramService: | ||
|
||
def __init__(self): | ||
self.BASE_URL = 'https://api.telegram.org/bot' | ||
self.TOKEN = settings.TG_TOKEN | ||
self.CHAT_ID = settings.TG_CHAT_ID | ||
|
||
def sendContactNotification(self, name, email, message): | ||
url = self.BASE_URL + self.TOKEN + '/sendMessage' | ||
message = f'<b>New Contact Message 📬</b>\nDear lord, you have received a new message from {name} ({email}), the message is the next one:\n\n<pre>{message}</pre>' | ||
payload = {'chat_id': self.CHAT_ID, 'parse_mode': 'HTML', 'text': message } | ||
r = requests.post(url, json=payload, timeout=5.0) | ||
print(r.status_code) | ||
print(r.text) | ||
return r.status_code == requests.codes.ok | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ psycopg2-binary==2.9.3 | |
dj-database-url==0.5.0 | ||
gunicorn==20.1.0 | ||
whitenoise==6.2.0 | ||
requests==2.28.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters