2018-06-18 17:44:48 +02:00
|
|
|
# Send a message
|
2017-12-22 02:24:30 +01:00
|
|
|
|
2020-04-28 20:00:46 +02:00
|
|
|
{generate_api_description(/messages:post)}
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2017-12-22 02:24:30 +01:00
|
|
|
## Usage examples
|
2018-06-18 17:44:48 +02:00
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{start_tabs}
|
|
|
|
{tab|python}
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{generate_code_example(python)|/messages:post|example}
|
|
|
|
|
|
|
|
{tab|js}
|
|
|
|
|
|
|
|
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
|
|
|
|
|
2020-05-17 12:29:49 +02:00
|
|
|
{generate_code_example(javascript)|/messages:post|example}
|
2018-09-17 16:27:32 +02:00
|
|
|
|
|
|
|
{tab|curl}
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2019-05-16 22:38:53 +02:00
|
|
|
``` curl
|
2018-06-18 17:44:48 +02:00
|
|
|
# For stream messages
|
2019-03-26 20:28:58 +01:00
|
|
|
curl -X POST {{ api_url }}/v1/messages \
|
2017-11-08 19:03:03 +01:00
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
|
|
|
|
-d "type=stream" \
|
|
|
|
-d "to=Denmark" \
|
|
|
|
-d "subject=Castle" \
|
2018-10-23 00:42:54 +02:00
|
|
|
-d $"content=I come not, friends, to steal away your hearts."
|
2018-06-18 17:44:48 +02:00
|
|
|
|
|
|
|
# For private messages
|
2019-03-26 20:28:58 +01:00
|
|
|
curl -X POST {{ api_url }}/v1/messages \
|
2018-06-18 17:44:48 +02:00
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
|
|
|
|
-d "type=private" \
|
2020-03-06 08:44:00 +01:00
|
|
|
-d "to=[9]" \
|
2018-10-23 00:42:54 +02:00
|
|
|
-d $"content=With mirth and laughter let old wrinkles come."
|
2017-11-08 19:03:03 +01:00
|
|
|
```
|
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{tab|zulip-send}
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
You can use `zulip-send`
|
2017-11-08 19:03:03 +01:00
|
|
|
(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-10-23 00:42:54 +02:00
|
|
|
--message "I come not, friends, to steal away your hearts." \
|
2017-11-08 19:03:03 +01:00
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
|
|
|
```
|
|
|
|
|
2020-06-18 15:35:25 +02:00
|
|
|
You can omit the `user` and `api-key` parameters if you have a `~/.zuliprc`
|
2018-06-18 17:44:48 +02:00
|
|
|
file.
|
2017-11-08 19:03:03 +01:00
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{end_tabs}
|
2017-12-22 02:31:40 +01:00
|
|
|
|
2020-06-18 15:35:25 +02:00
|
|
|
## Parameters
|
2018-01-20 22:03:05 +01:00
|
|
|
|
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
|
|
|
|
|
2020-05-20 11:57:57 +02:00
|
|
|
{generate_return_values_table|zulip.yaml|/messages:post}
|
2017-12-22 02:31:40 +01:00
|
|
|
|
|
|
|
#### 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
|
|
|
|
2020-04-17 19:16:43 +02:00
|
|
|
{generate_code_example|/messages:post|fixture(400_0)}
|
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:
|
|
|
|
|
2020-04-17 19:16:43 +02:00
|
|
|
{generate_code_example|/messages:post|fixture(400_1)}
|