Added a debug platform for debugging
This commit is contained in:
parent
bd3d948e8c
commit
31df433420
2 changed files with 41 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
from butterrobot.platforms.slack import SlackPlatform
|
||||
from butterrobot.platforms.telegram import TelegramPlatform
|
||||
from butterrobot.platforms.debug import DebugPlatform
|
||||
|
||||
|
||||
PLATFORMS = {platform.ID: platform for platform in (SlackPlatform, TelegramPlatform,)}
|
||||
PLATFORMS = {platform.ID: platform for platform in (SlackPlatform, TelegramPlatform, DebugPlatform)}
|
||||
|
|
39
butterrobot/platforms/debug.py
Normal file
39
butterrobot/platforms/debug.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import structlog
|
||||
|
||||
from butterrobot.platforms.base import Platform, PlatformMethods
|
||||
from butterrobot.objects import Message
|
||||
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
class DebugMethods(PlatformMethods):
|
||||
@classmethod
|
||||
async def send_message(self, message: Message):
|
||||
logger.debug(
|
||||
"Outgoing message", message=message.__dict__, platform=DebugPlatform.ID
|
||||
)
|
||||
|
||||
|
||||
class DebugPlatform(Platform):
|
||||
ID = "debug"
|
||||
|
||||
methods = DebugMethods
|
||||
|
||||
@classmethod
|
||||
async def parse_incoming_message(cls, request):
|
||||
request_data = await request.get_json()
|
||||
logger.debug("Parsing message", data=request_data, platform=cls.ID)
|
||||
|
||||
return Message(
|
||||
id=str(uuid.uuid4()),
|
||||
date=datetime.now(),
|
||||
text=request_data["text"],
|
||||
from_bot=bool(request_data.get("from_bot", False)),
|
||||
author=request_data.get("author", "Debug author"),
|
||||
chat=request_data.get("chat", "Debug chat ID"),
|
||||
raw={},
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue