Set "typing" status

POST https://rust-ml.zulipchat.com/api/v1/typing

Notify other users whether the current user is typing a message.

Clients implementing Zulip's typing notifications protocol should work as follows:

  • Send a request to this endpoint with op = "start" when a user starts typing a message, and also every TYPING_STARTED_WAIT_PERIOD = 10 seconds that the user continues to actively type or otherwise interact with the compose UI (e.g. interacting with the compose box emoji picker).
  • Send a request to this endpoint with op = "stop" when a user pauses using the compose UI for at least TYPING_STOPPED_WAIT_PERIOD = 5 seconds or cancels the compose action (if it had previously sent a "start" operation for that compose action).
  • Start displaying "Sender is typing" for a given conversation when the client receives an op = "start" event from the GET /events endpoint.
  • Continue displaying "Sender is typing" until they receive an op = "stop" event from the GET /events endpoint or TYPING_STARTED_EXPIRY_PERIOD = 15 seconds have passed without a new op = "start" event for that conversation.
  • Support for displaying stream typing notifications was new in Zulip 4.0 (feature level 58). Clients should indicate they support processing stream typing events via the stream_typing_notifications value in the client_capabilities parameter to POST /register endpoint.

This protocol is designed to allow the server-side typing notifications implementation to be stateless while being resilient; network failures cannot result in a user being incorrectly displayed as perpetually typing.

See the typing notification docs for additional design details on Zulip's typing notifications protocol.

Usage examples

#!/usr/bin/env python3

import zulip

# Pass the path to your zuliprc file here.
client = zulip.Client(config_file="~/zuliprc")

# The user has started to type in the group PM with Iago and Polonius
user_id1 = 10
user_id2 = 11

request = {
    "op": "start",
    "to": [user_id1, user_id2],
}
result = client.set_typing_status(request)

# The user has finished typing in the group PM with Iago and Polonius
user_id1 = 10
user_id2 = 11

request = {
    "op": "stop",
    "to": [user_id1, user_id2],
}
result = client.set_typing_status(request)

# The user has started to type in topic "typing status" of stream "Denmark"
stream_id = client.get_stream_id("Denmark")["stream_id"]
topic = "typing status"

request = {
    "type": "stream",
    "op": "start",
    "to": [stream_id],
    "topic": topic,
}
result = client.set_typing_status(request)

# The user has finished typing in topic "typing status" of stream "Denmark"
stream_id = client.get_stream_id("Denmark")["stream_id"]
topic = "typing status"

request = {
    "type": "stream",
    "op": "stop",
    "to": [stream_id],
    "topic": topic,
}
result = client.set_typing_status(request)

print(result)

More examples and documentation can be found here.

const zulipInit = require("zulip-js");

// Pass the path to your zuliprc file here.
const config = { zuliprc: "zuliprc" };

(async () => {
    const client = await zulipInit(config);

    const user_id1 = 9;
    const user_id2 = 10;

    const typingParams = {
        op: "start",
        to: [user_id1, user_id2],
    };

    // The user has started to type in the group PM with Iago and Polonius
    console.log(await client.typing.send(typingParams));
})();

curl -sSX POST https://rust-ml.zulipchat.com/api/v1/typing \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    --data-urlencode type=private \
    --data-urlencode op=start \
    --data-urlencode 'to=[9, 10]'

Parameters

type string optional

Example: "private"

Type of the message being composed.

Changes: New in Zulip 4.0 (feature level 58). Previously, typing notifications were only for private messages.

Must be one of: "private", "stream". Defaults to "private".


op string required

Example: "start"

Whether the user has started ("start") or stopped ("stop") typing.

Must be one of: "start", "stop".


to (integer)[] required

Example: [9, 10]

For "private" type it is the user_ids of the recipients of the message being typed. Send a JSON-encoded list of user_ids. (Use a list even if there is only one recipient.)

For "stream" type it is a single element list containing ID of stream in which the message is being typed.

Changes: Support for typing notifications for stream messages is new in Zulip 4.0 (feature level 58). Previously, typing notifications were only for private messages.

Before Zulip 2.0.0, this parameter accepted only a JSON-encoded list of email addresses. Support for the email address-based format was removed in Zulip 3.0 (feature level 11).


topic string optional

Example: "typing notifications"

Topic to which message is being typed. Required for the "stream" type. Ignored in the case of "private" type.

Changes: New in Zulip 4.0 (feature level 58). Previously, typing notifications were only for private messages.


Response

Example response

A typical successful JSON response may look like:

{
    "msg": "",
    "result": "success"
}

An example JSON error response for when user sends to multiple streams:

{
    "code": "BAD_REQUEST",
    "msg": "Cannot send to multiple streams",
    "result": "error"
}