Commit 22a6e77b authored by echel0n's avatar echel0n

Resolved issues with sending Telegram notifications.

parent 19624f65
......@@ -30,7 +30,7 @@ from sickrage.core.webserver.handlers.base import BaseHandler
from sickrage.providers import NewznabProvider, TorrentRssProvider
class ConfigProvidersHandler(BaseHandler):
class ConfigProvidersHandler(BaseHandler, ABC):
def get(self, *args, **kwargs):
return self.render(
......@@ -15,12 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <>.
from requests import HTTPError
from six.moves import urllib
import sickrage
from sickrage.core.websession import WebSession
from sickrage.notifiers import Notifiers
......@@ -56,35 +55,20 @@ class TelegramNotifier(Notifiers):
id = or id
api_key = or api_key'Telegram in use with API KEY: {}'.format(api_key))
payload = {'chat_id': id, 'text': '{} : {}'.format(title, msg)}
message = '{} : {}'.format(title.encode(), msg.encode())
payload = urllib.parse.urlencode({'chat_id': id, 'text': message})
telegram_api = '{}/{}'
req = urllib.request.Request(telegram_api.format(api_key, 'sendMessage'), payload)
success = False
message = 'Telegram message sent successfully.'
success = True
except IOError as e:
message = 'Unknown IO error: {}'.format(e)
if hasattr(e, 'code'):
error_message = {
400: 'Missing parameter(s). Double check your settings or if the channel/user exists.',
401: 'Authentication failed.',
420: 'Too many messages.',
500: 'Server error. Please retry in a few moments.',
if e.code in error_message:
message = error_message.get(e.code)
resp = WebSession().post(telegram_api.format(api_key, 'sendMessage'), json=payload).json()
success = resp['ok']
message = 'Telegram message sent successfully.' if success else '{} {}'.format(resp['error_code'], resp['description'])
except Exception as e:
success = False
message = 'Error while sending Telegram message: {} '.format(e)
return success, message
return success, message
def notify_snatch(self, ep_name, title=None):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment