mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
api: Document POST ../messages/{message_id}/reactions endpoint.
This refactors add_reaction in python_examples.py to use the
openapi_test_function decorator and validate result with
validate_against_openapi_schema. Minor changes have been made to the
OpenAPI format data for /messages/{message_id}/reactions endpoint.
This also adds add-emoji.md to templates/zerver/api and adds
add-emoji to rest-endpoints.md (templates/zerver/help/include).
This commit is contained in:
32
templates/zerver/api/add-emoji-reaction.md
Normal file
32
templates/zerver/api/add-emoji-reaction.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Add an emoji reaction
|
||||||
|
|
||||||
|
Add an [emoji reaction](/help/emoji-reactions) to a message.
|
||||||
|
|
||||||
|
`POST {{ api_url }}/v1/messages/{message_id}/reactions`
|
||||||
|
|
||||||
|
|
||||||
|
## Usage examples
|
||||||
|
|
||||||
|
{start_tabs}
|
||||||
|
{tab|python}
|
||||||
|
|
||||||
|
{generate_code_example(python)|/messages/{message_id}/reactions:post|example}
|
||||||
|
|
||||||
|
{tab|curl}
|
||||||
|
|
||||||
|
{generate_code_example(curl, exclude=["emoji_code","reaction_type"])|/messages/{message_id}/reactions:post|example}
|
||||||
|
|
||||||
|
{end_tabs}
|
||||||
|
|
||||||
|
## Arguments
|
||||||
|
|
||||||
|
|
||||||
|
{generate_api_arguments_table|zulip.yaml|/messages/{message_id}/reactions:post}
|
||||||
|
|
||||||
|
## Response
|
||||||
|
|
||||||
|
#### Example response
|
||||||
|
|
||||||
|
A typical successful JSON response may look like:
|
||||||
|
|
||||||
|
{generate_code_example|/messages/{message_id}/reactions:post|fixture(200)}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
* [Get a raw message](/api/get-raw-message)
|
* [Get a raw message](/api/get-raw-message)
|
||||||
* [Send a message](/api/send-message)
|
* [Send a message](/api/send-message)
|
||||||
* [Update a message](/api/update-message)
|
* [Update a message](/api/update-message)
|
||||||
|
* [Add an emoji reaction](/api/add-emoji-reaction)
|
||||||
* [Render a message](/api/render-message)
|
* [Render a message](/api/render-message)
|
||||||
* [Upload a file](/api/upload-file)
|
* [Upload a file](/api/upload-file)
|
||||||
* [Delete a message](/api/delete-message)
|
* [Delete a message](/api/delete-message)
|
||||||
|
|||||||
@@ -698,25 +698,26 @@ def send_message(client):
|
|||||||
|
|
||||||
return message_id
|
return message_id
|
||||||
|
|
||||||
|
@openapi_test_function("/messages/{message_id}/reactions:post")
|
||||||
def add_reaction(client, message_id):
|
def add_reaction(client, message_id):
|
||||||
# type: (Client, int) -> None
|
# type: (Client, int) -> None
|
||||||
|
# {code_example|start}
|
||||||
|
# Add an emoji reaction
|
||||||
request = {
|
request = {
|
||||||
'message_id': str(message_id),
|
'message_id': str(message_id),
|
||||||
'emoji_name': 'joy',
|
'emoji_name': 'octopus',
|
||||||
'emoji_code': '1f602',
|
|
||||||
'emoji_type': 'unicode_emoji'
|
|
||||||
}
|
}
|
||||||
result = client.add_reaction(request)
|
|
||||||
|
|
||||||
assert result['result'] == 'success'
|
result = client.add_reaction(request)
|
||||||
|
# {code_example|end}
|
||||||
|
validate_against_openapi_schema(result, '/messages/{message_id}/reactions', 'post', '200')
|
||||||
|
|
||||||
@openapi_test_function("/messages/{message_id}/reactions:delete")
|
@openapi_test_function("/messages/{message_id}/reactions:delete")
|
||||||
def remove_reaction(client, message_id):
|
def remove_reaction(client, message_id):
|
||||||
# type: (Client, int) -> None
|
# type: (Client, int) -> None
|
||||||
request = {
|
request = {
|
||||||
'message_id': str(message_id),
|
'message_id': str(message_id),
|
||||||
'emoji_name': 'joy',
|
'emoji_name': 'octopus',
|
||||||
'emoji_code': '1f602',
|
|
||||||
'reaction_type': 'unicode_emoji'
|
'reaction_type': 'unicode_emoji'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -845,17 +845,26 @@ paths:
|
|||||||
you want, and note that emoji's text name.
|
you want, and note that emoji's text name.
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
example: '**:slight smile:**'
|
example: 'octopus'
|
||||||
required: true
|
required: true
|
||||||
- name: emoji_code
|
- name: emoji_code
|
||||||
in: query
|
in: query
|
||||||
description: |
|
description: |
|
||||||
An encoded version of the unicode codepoint. Used only
|
An encoded version of the unicode codepoint. For
|
||||||
in rare corner cases to consolidate identical reactions
|
most clients, you won't need this; it's used to
|
||||||
to the same emoji name.
|
handle a rare corner case when upvoting a unicode
|
||||||
|
emoji reaction added previously by another user.
|
||||||
|
|
||||||
|
If the existing reaction was added when the Zulip
|
||||||
|
server was using a previous version of the emoji
|
||||||
|
data mapping from codepoints to human-readable
|
||||||
|
names, sending the `emoji_code` in the data for
|
||||||
|
the original reaction allows the Zulip server to
|
||||||
|
correctly consider your upvote as an upvote
|
||||||
|
rather than a reaction with a "diffenent" emoji.
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
example: '**foo**'
|
example: '1f419'
|
||||||
required: false
|
required: false
|
||||||
- name: reaction_type
|
- name: reaction_type
|
||||||
in: query
|
in: query
|
||||||
@@ -864,7 +873,7 @@ paths:
|
|||||||
set `reaction_type` to `realm_emoji`.
|
set `reaction_type` to `realm_emoji`.
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
example: '**realm_emoji**'
|
example: 'unicode_emoji'
|
||||||
required: false
|
required: false
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
@@ -874,16 +883,26 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/JsonSuccess'
|
- $ref: '#/components/schemas/JsonSuccess'
|
||||||
- properties:
|
- example:
|
||||||
rendered:
|
{
|
||||||
type: string
|
"result": "success",
|
||||||
description: The rendered HTML.
|
"msg": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
'400':
|
||||||
|
description: Bad request.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/CodedError'
|
||||||
- example:
|
- example:
|
||||||
{
|
{
|
||||||
"msg": "",
|
"result": "error",
|
||||||
"rendered": "<p><strong>foo</strong></p>",
|
"msg": "Invalid emoji code",
|
||||||
"result": "success"
|
"code": "BAD_REQUEST"
|
||||||
}
|
}
|
||||||
|
|
||||||
delete:
|
delete:
|
||||||
description: Delete an emoji reaction from a message.
|
description: Delete an emoji reaction from a message.
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
Reference in New Issue
Block a user