Stream message

Send a message to a stream.

POST https://zulip.sagemath.org/api/v1/messages

Usage examples

curl https://zulip.sagemath.org/api/v1/messages \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    -d "type=stream" \
    -d "to=Denmark" \
    -d "subject=Castle" \
    -d "content=Something is rotten in the state of Denmark."
#!/usr/bin/env python3

import zulip

# Download ~/zuliprc-dev from your dev server
client = zulip.Client(config_file="~/zuliprc-dev")

# Send a stream message
request = {
    "type": "stream",
    "to": "Denmark",
    "subject": "Castle",
    "content": "Something is rotten in the state of Denmark."
}
result = client.send_message(request)
print(result)

You can use zulip-send (available after you pip install zulip) to easily send Zulips from the command-line, providing the message content via STDIN.

zulip-send --stream Denmark --subject Castle \
    --user [email protected] --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5

Passing in the message on the command-line

If you'd like, you can also provide the message on the command-line with the -m flag, as follows:

zulip-send --stream Denmark --subject Castle \
    -m "Something is rotten in the state of Denmark." \
    --user [email protected] --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5

You can omit the user and api-key arguments if you have a ~/.zuliprc file.

See also the full API endpoint documentation.

More examples and documentation can be found here.

const zulip = require('zulip-js');

// Download zuliprc-dev from your dev server
const config = {
    zuliprc: 'zuliprc-dev',
};

zulip(config).then((client) => {
    // Send a message
    const params = {
        to: 'Denmark',
        type: 'stream',
        subject: 'Castle',
        content: 'Something is rotten in the state of Denmark.'
    }

    client.messages.send(params).then(console.log);
});

Arguments

Argument Example Required Description
type stream Required

The type of message to be sent. stream for a stream message and private for a private message.

to Denmark Required

A string identifying the stream.

subject Castle Optional

The topic of the message. Only required if type is stream. Defaults to None. Maximum length of 60 characters.

content Hello Required

The content of the message. Maximum message size of 10000 bytes.

Response

Return values

  • id: The ID of the newly created message

Example response

A typical successful JSON response may look like:

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

A typical failed JSON response for when the target stream does not exist:

{
    "code": "STREAM_DOES_NOT_EXIST",
    "msg": "Stream 'nonexistent_stream' does not exist",
    "result": "error",
    "stream": "nonexistent_stream"
}