Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

embedded bot: Return message id for send_message and send_reply.

PIG208427506b7422f
diff --git a/zerver/lib/bot_lib.py b/zerver/lib/bot_lib.py
index 2180412f882..e179b2de470 100644
--- a/zerver/lib/bot_lib.py
+++ b/zerver/lib/bot_lib.py
@@ -86,19 +86,19 @@ class EmbeddedBotHandler:
def react(self, message: Dict[str, Any], emoji_name: str) -> Dict[str, Any]:
return {} # Not implemented
- def send_message(self, message: Dict[str, Any]) -> None:
+ def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
if not self._rate_limit.is_legal():
self._rate_limit.show_error_and_exit()
if message["type"] == "stream":
- internal_send_stream_message_by_name(
+ message_id = internal_send_stream_message_by_name(
self.user_profile.realm,
self.user_profile,
message["to"],
message["topic"],
message["content"],
)
- return
+ return {"id": message_id}
assert message["type"] == "private"
# Ensure that it's a comma-separated list, even though the
@@ -109,17 +109,20 @@ class EmbeddedBotHandler:
raise EmbeddedBotEmptyRecipientsList(_("Message must have recipients!"))
elif len(message["to"]) == 1:
recipient_user = get_active_user(recipients[0], self.user_profile.realm)
- internal_send_private_message(self.user_profile, recipient_user, message["content"])
+ message_id = internal_send_private_message(
+ self.user_profile, recipient_user, message["content"]
+ )
else:
- internal_send_huddle_message(
+ message_id = internal_send_huddle_message(
self.user_profile.realm, self.user_profile, recipients, message["content"]
)
+ return {"id": message_id}
def send_reply(
self, message: Dict[str, Any], response: str, widget_content: Optional[str] = None
- ) -> None:
+ ) -> Dict[str, Any]:
if message["type"] == "private":
- self.send_message(
+ result = self.send_message(
dict(
type="private",
to=[x["email"] for x in message["display_recipient"]],
@@ -128,7 +131,7 @@ class EmbeddedBotHandler:
)
)
else:
- self.send_message(
+ result = self.send_message(
dict(
type="stream",
to=message["display_recipient"],
@@ -137,6 +140,7 @@ class EmbeddedBotHandler:
sender_email=message["sender_email"],
)
)
+ return {"id": result["id"]}
def update_message(self, message: Dict[str, Any]) -> None:
pass # Not implemented