Added author information to message
This commit is contained in:
parent
e1c158bd6c
commit
562d7138c0
4 changed files with 19 additions and 4 deletions
|
@ -17,7 +17,9 @@ logger = structlog.get_logger(__name__)
|
|||
app = Quart(__name__)
|
||||
available_platforms = {}
|
||||
plugins = get_available_plugins()
|
||||
enabled_plugins = [plugin for plugin_name, plugin in plugins.items() if plugin_name in ENABLED_PLUGINS]
|
||||
enabled_plugins = [
|
||||
plugin for plugin_name, plugin in plugins.items() if plugin_name in ENABLED_PLUGINS
|
||||
]
|
||||
|
||||
|
||||
@app.before_serving
|
||||
|
@ -39,11 +41,18 @@ async def incoming_platform_message_view(platform, path=None):
|
|||
return {"error": "Unknown platform"}, 400
|
||||
|
||||
try:
|
||||
message = await available_platforms[platform].parse_incoming_message(request=request)
|
||||
message = await available_platforms[platform].parse_incoming_message(
|
||||
request=request
|
||||
)
|
||||
except Platform.PlatformAuthResponse as response:
|
||||
return response.data, response.status_code
|
||||
except Exception as error:
|
||||
logger.error(f"Error parsing message", platform=platform, error=error, traceback=traceback.format_exc())
|
||||
logger.error(
|
||||
f"Error parsing message",
|
||||
platform=platform,
|
||||
error=error,
|
||||
traceback=traceback.format_exc(),
|
||||
)
|
||||
return {"error": str(error)}, 400
|
||||
|
||||
if not message:
|
||||
|
@ -53,7 +62,7 @@ async def incoming_platform_message_view(platform, path=None):
|
|||
if result := await plugin.on_message(message):
|
||||
if isinstance(result, Message):
|
||||
result = [result]
|
||||
|
||||
|
||||
for out_message in result:
|
||||
await available_platforms[platform].methods.send_message(out_message)
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ from typing import Text, Optional
|
|||
class Message:
|
||||
text: Text
|
||||
chat: Text
|
||||
author: Text
|
||||
is_bot: bool = False
|
||||
date: Optional[datetime] = None
|
||||
id: Optional[Text] = None
|
||||
reply_to: Optional[Text] = None
|
||||
|
|
|
@ -63,6 +63,8 @@ class SlackPlatform(Platform):
|
|||
|
||||
return Message(
|
||||
id=data["event"].get("thread_ts", data["event"]["ts"]),
|
||||
author=data["event"]["user"],
|
||||
is_bot="bot_id" in data["event"],
|
||||
date=datetime.fromtimestamp(int(float(data["event"]["event_ts"]))),
|
||||
text=data["event"]["text"],
|
||||
chat=data["event"]["channel"],
|
||||
|
|
|
@ -61,6 +61,8 @@ class TelegramPlatform(Platform):
|
|||
id=request_data["message"]["message_id"],
|
||||
date=datetime.fromtimestamp(request_data["message"]["date"]),
|
||||
text=str(request_data["message"]["text"]),
|
||||
is_bot=request_data["message"]["from"]["is_bot"],
|
||||
author=request_data["message"]["from"]["id"],
|
||||
chat=str(request_data["message"]["chat"]["id"]),
|
||||
raw=request_data,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue