-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from ilstreltsov/telegram_bot
Telegram bot
- Loading branch information
Showing
6 changed files
with
77 additions
and
6 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
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,27 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from dbmail.defaults import BOT_PROVIDER, DEFAULT_BOT_FROM | ||
from dbmail.backends.sms import ( | ||
Sender as SenderBase, | ||
SenderDebug as SenderDebugBase | ||
) | ||
from dbmail.utils import clean_html | ||
from dbmail import import_module | ||
|
||
|
||
class Sender(SenderBase): | ||
provider = BOT_PROVIDER | ||
default_from = DEFAULT_BOT_FROM | ||
|
||
def _get_recipient_list(self, recipient): | ||
return self._email_to_list(recipient) | ||
|
||
def _send(self): | ||
module = import_module(self._provider) | ||
message = clean_html(self._message) | ||
for _id in self._recipient_list: | ||
module.send(_id, message, _from=self._from_email, **self._kwargs) | ||
|
||
|
||
class SenderDebug(SenderDebugBase): | ||
pass |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# coding=utf-8; |
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,29 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
import telepot | ||
from django.conf import settings | ||
|
||
|
||
def send(to, message, **kwargs): | ||
""" | ||
SITE: https://github.com/nickoala/telepot | ||
TELEGRAM API: https://core.telegram.org/bots/api | ||
Installation: | ||
pip install 'telepot>=10.4' | ||
""" | ||
|
||
available_kwargs_keys = [ | ||
'parse_mode', | ||
'disable_web_page_preview', | ||
'disable_notification', | ||
'reply_to_message_id', | ||
'reply_markup' | ||
] | ||
|
||
available_kwargs = { | ||
k: v for k, v in kwargs.iteritems() if k in available_kwargs_keys | ||
} | ||
|
||
bot = telepot.Bot(settings.TELEGRAM_BOT_TOKEN) | ||
return bot.sendMessage(to, message, **available_kwargs) |
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