embedded bot: Return message id for send_message and send_reply.

This change is made to comply with the corresponding views for
the API. The incrementor implementation in zulip_bots won't work
otherwise if send_message and send_reply return None as it needs
the message id.
This commit is contained in:
PIG208
2021-04-04 05:02:39 +08:00
committed by Tim Abbott
parent 3f4d0f72fd
commit 427506b742

View File

@@ -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