2018-06-18 17:44:48 +02:00
|
|
|
# Send a message
|
2017-12-22 02:24:30 +01:00
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
Send a stream or a private message.
|
2017-12-22 02:24:30 +01:00
|
|
|
|
2017-12-22 02:31:40 +01:00
|
|
|
`POST {{ api_url }}/v1/messages`
|
|
|
|
|
2017-12-22 02:24:30 +01:00
|
|
|
## Usage examples
|
2018-06-18 17:44:48 +02:00
|
|
|
|
2017-11-08 19:03:03 +01:00
|
|
|
<div class="code-section" markdown="1">
|
|
|
|
<ul class="nav">
|
|
|
|
<li data-language="python">Python</li>
|
|
|
|
<li data-language="javascript">JavaScript</li>
|
2018-01-22 22:49:30 +01:00
|
|
|
<li data-language="curl">curl</li>
|
|
|
|
<li data-language="zulip-send">zulip-send</li>
|
2017-11-08 19:03:03 +01:00
|
|
|
</ul>
|
|
|
|
<div class="blocks">
|
|
|
|
|
|
|
|
<div data-language="curl" markdown="1">
|
|
|
|
|
|
|
|
```
|
2018-06-18 17:44:48 +02:00
|
|
|
# For stream messages
|
2017-11-08 19:03:03 +01:00
|
|
|
curl {{ api_url }}/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."
|
2018-06-18 17:44:48 +02:00
|
|
|
|
|
|
|
# For private messages
|
|
|
|
curl {{ api_url }}/v1/messages \
|
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
|
|
|
|
-d "type=private" \
|
|
|
|
-d "to=hamlet@example.com" \
|
|
|
|
-d "content=I come not, friends, to steal away your hearts."
|
2017-11-08 19:03:03 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="python" markdown="1">
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
{generate_code_example(python)|/messages:post|example}
|
2017-11-08 19:03:03 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="zulip-send" markdown="1"> 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.
|
|
|
|
|
|
|
|
```bash
|
2018-06-18 17:44:48 +02:00
|
|
|
# For stream messages
|
2017-11-08 19:03:03 +01:00
|
|
|
zulip-send --stream Denmark --subject Castle \
|
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
2018-06-18 17:44:48 +02:00
|
|
|
|
|
|
|
# For private messages
|
|
|
|
zulip-send hamlet@example.com \
|
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
2017-11-08 19:03:03 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Passing in the message on the command-line
|
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
If you'd like, you can also provide the message on the command-line with the
|
|
|
|
`-m` or `--message` flag, as follows:
|
2017-11-08 19:03:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
zulip-send --stream Denmark --subject Castle \
|
2018-06-18 17:44:48 +02:00
|
|
|
--message "Something is rotten in the state of Denmark." \
|
2017-11-08 19:03:03 +01:00
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
|
|
|
```
|
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
You can omit the `user` and `api-key` arguments if you have a `~/.zuliprc`
|
|
|
|
file.
|
2017-11-08 19:03:03 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="javascript" markdown="1">
|
|
|
|
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
|
|
|
|
```js
|
2017-12-28 23:42:59 +01:00
|
|
|
const zulip = require('zulip-js');
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2018-01-13 22:36:23 +01:00
|
|
|
// Download zuliprc-dev from your dev server
|
2017-11-08 19:03:03 +01:00
|
|
|
const config = {
|
2018-01-13 22:36:23 +01:00
|
|
|
zuliprc: 'zuliprc-dev',
|
2017-11-08 19:03:03 +01:00
|
|
|
};
|
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
// Send a stream message
|
2018-01-13 22:36:23 +01:00
|
|
|
zulip(config).then((client) => {
|
|
|
|
// Send a message
|
|
|
|
const params = {
|
|
|
|
to: 'Denmark',
|
|
|
|
type: 'stream',
|
|
|
|
subject: 'Castle',
|
|
|
|
content: 'Something is rotten in the state of Denmark.'
|
|
|
|
}
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2018-01-13 22:36:23 +01:00
|
|
|
client.messages.send(params).then(console.log);
|
2017-11-08 19:03:03 +01:00
|
|
|
});
|
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
// Send a private message
|
|
|
|
zulip(config).then((client) => {
|
|
|
|
// Send a private message
|
|
|
|
const params = {
|
|
|
|
to: 'hamlet@example.com',
|
|
|
|
type: 'private',
|
|
|
|
content: 'I come not, friends, to steal away your hearts.',
|
|
|
|
}
|
|
|
|
|
|
|
|
client.messages.send(params).then(console.log);
|
|
|
|
});
|
|
|
|
|
2017-11-08 19:03:03 +01:00
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2018-01-20 22:03:05 +01:00
|
|
|
## Arguments
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
{generate_api_arguments_table|zulip.yaml|/messages:post}
|
2018-01-20 22:03:05 +01:00
|
|
|
|
2017-12-22 02:31:40 +01:00
|
|
|
## Response
|
|
|
|
|
|
|
|
#### Return values
|
|
|
|
|
|
|
|
* `id`: The ID of the newly created message
|
|
|
|
|
|
|
|
#### Example response
|
2018-01-27 22:26:16 +01:00
|
|
|
A typical successful JSON response may look like:
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
{generate_code_example|/messages:post|fixture(200)}
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
A typical failed JSON response for when a stream message is sent to a stream
|
|
|
|
that does not exist:
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
{generate_code_example|/messages:post|fixture(400_non_existing_stream)}
|
2018-06-18 17:44:48 +02:00
|
|
|
|
|
|
|
A typical failed JSON response for when a private message is sent to a user
|
|
|
|
that does not exist:
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
{generate_code_example|/messages:post|fixture(400_non_existing_user)}
|