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.

api_docs: Add response details to outgoing webhooks documentation.

orientor12efa41ed673
diff --git a/templates/zerver/api/outgoing-webhooks.md b/templates/zerver/api/outgoing-webhooks.md
index bd035f9644c..de85b1e17d0 100644
--- a/templates/zerver/api/outgoing-webhooks.md
+++ b/templates/zerver/api/outgoing-webhooks.md
@@ -35,61 +35,9 @@ There are currently two ways to trigger an outgoing webhook:
## Zulip message format
-The Zulip-format webhook messages post the following data, encoded as JSON:
+### Return values
-<table class="table">
- <thead>
- <tr>
- <th>Name</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>bot_email</code></td>
- <td>Email of the bot user</td>
- </tr>
- <tr>
- <td><code>data</code></td>
- <td>The content of the message (in Markdown)</td>
- </tr>
- <tr>
- <td><code>message</code></td>
- <td>A dict containing details on the message which
- triggered the outgoing webhook</td>
- </tr>
- <tr>
- <td><code>token</code></td>
- <td>A string of alphanumeric characters you can use to
- authenticate the webhook request (each bot user uses a fixed token)</td>
- </tr>
- <tr>
- <td><code>trigger</code></td>
- <td>Trigger method</td>
- </tr>
- </tbody>
-</table>
-
-Some of the important fields in the `message` dict include the following:
-
-<table class="table">
- <thead>
- <tr>
- <th>Name</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>recipient_id</code></td>
- <td>Unique ID of the stream that will persist even if the stream is renamed</td>
- </tr>
- <tr>
- <td><code>rendered_content</code></td>
- <td>The content of the message, rendered in HTML</td>
- </tr>
- </tbody>
-</table>
+{generate_return_values_table|zulip.yaml|/zulip-outgoing-webhook:post}
A correctly implemented endpoint will do the following:
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 0fd967d4ba1..f5b3356b071 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -8331,6 +8331,10 @@ paths:
type: object
additionalProperties: false
properties:
+ bot_email:
+ type: string
+ description: |
+ Email of the bot user.
data:
type: string
description: |
@@ -8343,8 +8347,8 @@ paths:
token:
type: string
description: |
- A string of alphanumeric characters that can be use to authenticate the
- webhook request. You can get the token used by a given outgoing webhook bot
+ A string of alphanumeric characters that can be used to authenticate the
+ webhook request (each bot user uses a fixed token). You can get the token used by a given outgoing webhook bot
in the `zuliprc` file downloaded when creating the bot.
message:
allOf:
@@ -8357,10 +8361,6 @@ paths:
type: string
description: |
The content/body of the message rendered in HTML.
- bot_email:
- type: string
- description: |
- Email of the bot user.
example:
{
"data": "@**Outgoing Webhook Test** Zulip is the world\u2019s most productive group chat!",
diff --git a/zerver/tests/test_outgoing_webhook_interfaces.py b/zerver/tests/test_outgoing_webhook_interfaces.py
index bdb38dcbd26..6e7640591b6 100644
--- a/zerver/tests/test_outgoing_webhook_interfaces.py
+++ b/zerver/tests/test_outgoing_webhook_interfaces.py
@@ -11,6 +11,7 @@ from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.topic import TOPIC_NAME
from zerver.models import SLACK_INTERFACE, Message, get_realm, get_stream, get_user
+from zerver.openapi.openapi import validate_against_openapi_schema
class TestGenericOutgoingWebhookService(ZulipTestCase):
@@ -107,6 +108,7 @@ class TestGenericOutgoingWebhookService(ZulipTestCase):
request_data = self.handler.build_bot_request(event)
request_data = json.loads(request_data)
+ validate_against_openapi_schema(request_data, '/zulip-outgoing-webhook', 'post', '200')
self.assertEqual(request_data['data'], "@**test**")
self.assertEqual(request_data['token'], "abcdef")
self.assertEqual(request_data['message'], expected_message_data)