butterrobot/butterrobot/platforms/base.py

68 lines
1.6 KiB
Python
Raw Normal View History

from abc import abstractmethod
2020-04-22 21:58:06 +00:00
from dataclasses import dataclass
class Platform:
class PlatformError(Exception):
pass
class PlatformInitError(PlatformError):
pass
class PlatformAuthError(PlatformError):
pass
@dataclass
class PlatformAuthResponse(PlatformError):
"""
Used when the platform needs to make a response right away instead of async.
"""
2020-04-22 21:58:06 +00:00
data: dict
status_code: int = 200
@classmethod
2020-10-28 10:19:30 +00:00
def init(cls, app):
"""
Initialises the platform.
Used at the application launch to prepare anything required for
the platform to work..
It receives the flask application via parameter in case the platform
requires for custom webservice endpoints or configuration.
"""
2020-04-22 21:58:06 +00:00
pass
@classmethod
@abstractmethod
def parse_incoming_message(cls, request):
"""
Parses the incoming request and returns a :class:`butterrobot.objects.Message` instance.
"""
pass
2020-04-22 21:58:06 +00:00
@classmethod
@abstractmethod
def parse_channel_name_from_raw(cls, channel_raw) -> str:
"""
Extracts the Channel name from :class:`butterrobot.objects.Channel.channel_raw`.
"""
2020-04-22 21:58:06 +00:00
pass
@classmethod
@abstractmethod
def parse_channel_from_message(cls, channel_raw):
"""
Extracts the Channel raw data from the message received in the incoming webhook.
"""
pass
class PlatformMethods:
@classmethod
@abstractmethod
def send_message(cls, message):
"""Method used to send a message via the platform"""
2020-04-22 21:58:06 +00:00
pass