2017-07-25 02:37:04 +02:00
|
|
|
# Installation instructions
|
|
|
|
|
|
|
|
#### Python Installation
|
|
|
|
Install it with [pip](https://pypi.python.org/pypi/zulip/):
|
|
|
|
```
|
|
|
|
pip install zulip
|
|
|
|
```
|
|
|
|
#### JavaScript Installation
|
|
|
|
Install it with [npm](https://www.npmjs.com/package/zulip-js):
|
|
|
|
```
|
|
|
|
npm install zulip-js
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage examples
|
|
|
|
<div class="code-section" markdown="1">
|
|
|
|
<ul class="nav">
|
|
|
|
<li data-language="curl">curl</li>
|
|
|
|
<li data-language="python">Python</li>
|
|
|
|
<li data-language="zulip-send">zulip-send</li>
|
|
|
|
<li data-language="javascript">JavaScript</li>
|
|
|
|
</ul>
|
|
|
|
<div class="blocks">
|
|
|
|
|
|
|
|
<div data-language="curl" markdown="1">
|
|
|
|
No download required!
|
|
|
|
|
|
|
|
#### Stream message
|
|
|
|
|
|
|
|
```
|
|
|
|
curl {{ api_url }}/v1/messages \
|
2017-11-08 01:06:53 +01:00
|
|
|
-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."
|
2017-07-25 02:37:04 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Private message
|
|
|
|
```
|
|
|
|
curl {{ api_url }}/v1/messages \
|
2017-11-08 01:06:53 +01:00
|
|
|
-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-07-25 02:37:04 +02:00
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="python" markdown="1">
|
|
|
|
```python
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import zulip
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Keyword arguments 'email' and 'api_key' are not required if you are using ~/.zuliprc
|
|
|
|
client = zulip.Client(email="othello-bot@example.com",
|
2017-11-08 01:06:53 +01:00
|
|
|
api_key="a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5",
|
|
|
|
site="{{ api_url }}")
|
|
|
|
|
2017-07-25 02:37:04 +02:00
|
|
|
# Send a stream message
|
|
|
|
client.send_message({
|
2017-11-08 01:06:53 +01:00
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
|
|
|
"subject": "Castle",
|
|
|
|
"content": "Something is rotten in the state of Denmark."
|
2017-07-25 02:37:04 +02:00
|
|
|
})
|
|
|
|
# Send a private message
|
|
|
|
client.send_message({
|
2017-11-08 01:06:53 +01:00
|
|
|
"type": "private",
|
|
|
|
"to": "hamlet@example.com",
|
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
2017-07-25 02:37:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
# Print each message the user receives
|
|
|
|
# This is a blocking call that will run forever
|
|
|
|
client.call_on_each_message(lambda msg: sys.stdout.write(str(msg) + "\n"))
|
|
|
|
|
|
|
|
# Print every event relevant to the user
|
|
|
|
# This is a blocking call that will run forever
|
|
|
|
# This will never be reached unless you comment out the previous line
|
|
|
|
client.call_on_each_event(lambda msg: sys.stdout.write(str(msg) + "\n"))
|
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
2017-11-08 18:44:55 +01:00
|
|
|
<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.
|
2017-07-25 02:37:04 +02:00
|
|
|
|
|
|
|
#### Stream message
|
|
|
|
|
|
|
|
```bash
|
|
|
|
zulip-send --stream Denmark --subject Castle \
|
2017-11-08 18:43:41 +01:00
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
2017-07-25 02:37:04 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Private message
|
|
|
|
|
|
|
|
```bash
|
|
|
|
zulip-send hamlet@example.com \
|
2017-11-08 18:43:41 +01:00
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
2017-07-25 02:37:04 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
#### 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:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
zulip-send --stream Denmark --subject Castle \
|
2017-11-08 18:43:41 +01:00
|
|
|
-m "Something is rotten in the state of Denmark." \
|
|
|
|
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5
|
2017-07-25 02:37:04 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
You can omit the `user` and `api-key` arguments if you have a `~/.zuliprc` file.
|
|
|
|
|
|
|
|
See also the [full API endpoint documentation.](/api/endpoints).
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div data-language="javascript" markdown="1">
|
|
|
|
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
|
|
|
|
```js
|
|
|
|
const zulip = require('zulip');
|
|
|
|
|
|
|
|
const config = {
|
2017-11-08 01:06:53 +01:00
|
|
|
username: 'othello-bot@example.com',
|
|
|
|
apiKey: 'a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5',
|
|
|
|
realm: '{{ api_url }}'
|
2017-07-25 02:37:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const client = zulip(config);
|
|
|
|
|
|
|
|
// Send a message
|
|
|
|
client.messages.send({
|
2017-11-08 01:06:53 +01:00
|
|
|
to: 'Denmark',
|
|
|
|
type: 'stream',
|
|
|
|
subject: 'Castle',
|
|
|
|
content: 'Something is rotten in the state of Denmark.'
|
2017-07-25 02:37:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Send a private message
|
|
|
|
client.messages.send({
|
2017-11-08 01:06:53 +01:00
|
|
|
to: 'hamlet@example.com',
|
|
|
|
type: 'private',
|
|
|
|
content: 'I come not, friends, to steal away your hearts.'
|
2017-07-25 02:37:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Register queue to receive messages for user
|
|
|
|
client.queues.register({
|
2017-11-08 01:06:53 +01:00
|
|
|
event_types: ['message']
|
2017-07-25 02:37:04 +02:00
|
|
|
}).then((res) => {
|
2017-11-08 01:06:53 +01:00
|
|
|
// Retrieve events from a queue
|
|
|
|
// Blocking until there is an event (or the request times out)
|
|
|
|
client.events.retrieve({
|
|
|
|
queue_id: res.queue_id,
|
|
|
|
last_event_id: -1,
|
|
|
|
dont_block: false
|
|
|
|
}).then(console.log);
|
2017-07-25 02:37:04 +02:00
|
|
|
});
|
|
|
|
```
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|