2018-04-28 02:01:41 +02:00
|
|
|
# Get events from an event queue
|
2018-01-04 00:07:26 +01:00
|
|
|
|
|
|
|
`GET {{ api_url }}/v1/events`
|
|
|
|
|
2018-04-28 02:01:41 +02:00
|
|
|
This endpoint allows you to receive new events from
|
|
|
|
[a registered event queue](/api/register-queue).
|
2018-01-04 00:07:26 +01:00
|
|
|
|
|
|
|
## Usage examples
|
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{start_tabs}
|
|
|
|
{tab|python}
|
2018-01-04 00:07:26 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import zulip
|
|
|
|
|
|
|
|
# Download ~/zuliprc-dev from your dev server
|
|
|
|
client = zulip.Client(config_file="~/zuliprc-dev")
|
|
|
|
|
|
|
|
# If you already have a queue registered and thus, have a queue_id
|
|
|
|
# on hand, you may use client.get_events() and pass in the above
|
|
|
|
# arguments, like so:
|
|
|
|
print(client.get_events(
|
|
|
|
queue_id="1515010080:4",
|
|
|
|
last_event_id=-1
|
|
|
|
))
|
|
|
|
```
|
|
|
|
|
|
|
|
`call_on_each_message` and `call_on_each_event` will automatically register
|
|
|
|
a queue for you.
|
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{tab|js}
|
2018-01-04 00:07:26 +01:00
|
|
|
|
|
|
|
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
|
|
|
|
```js
|
|
|
|
const zulip = require('zulip-js');
|
|
|
|
|
2018-01-13 23:55:23 +01:00
|
|
|
// Download zuliprc-dev from your dev server
|
2018-01-04 00:07:26 +01:00
|
|
|
const config = {
|
2018-01-13 23:55:23 +01:00
|
|
|
zuliprc: 'zuliprc-dev',
|
2018-01-04 00:07:26 +01:00
|
|
|
};
|
|
|
|
|
2018-01-13 23:55:23 +01:00
|
|
|
zulip(config).then((client) => {
|
|
|
|
// Register queue to receive messages for user
|
|
|
|
const queueParams = {
|
|
|
|
event_types: ['message']
|
|
|
|
};
|
|
|
|
client.queues.register(queueParams).then((res) => {
|
|
|
|
// Retrieve events from a queue
|
|
|
|
// Blocking until there is an event (or the request times out)
|
|
|
|
const eventParams = {
|
|
|
|
queue_id: res.queue_id,
|
|
|
|
last_event_id: -1,
|
|
|
|
dont_block: false,
|
|
|
|
};
|
|
|
|
client.events.retrieve(eventParams).then(console.log);
|
|
|
|
});
|
2018-01-04 00:07:26 +01:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{tab|curl}
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -G {{ api_url }}/v1/events \
|
|
|
|
-u BOT_EMAIL_ADDRESS:BOT_API_KEY
|
|
|
|
-d "queue_id=1375801870:2942" \
|
|
|
|
-d "last_event_id=-1"
|
|
|
|
```
|
2018-01-04 00:07:26 +01:00
|
|
|
|
2018-09-17 16:27:32 +02:00
|
|
|
{end_tabs}
|
2018-01-04 00:07:26 +01:00
|
|
|
|
2018-01-20 22:03:05 +01:00
|
|
|
## Arguments
|
|
|
|
|
2018-06-21 01:05:11 +02:00
|
|
|
{generate_api_arguments_table|zulip.yaml|/events:get}
|
2018-01-20 22:03:05 +01:00
|
|
|
|
|
|
|
**Note**: The arguments documented above are optional in the sense that
|
|
|
|
even if you haven't registered a queue by explicitly requesting the
|
|
|
|
`{{ api_url}}/v1/register` endpoint, you could pass the arguments for
|
|
|
|
[the `{{ api_url}}/v1/register` endpoint](/api/register-queue) to this
|
|
|
|
endpoint and a queue would be registered in the absence of a `queue_id`.
|
|
|
|
|
2018-01-04 00:07:26 +01:00
|
|
|
## Response
|
|
|
|
|
|
|
|
#### Return values
|
|
|
|
|
|
|
|
* `events`: An array (possibly zero-length if `dont_block` is set) of events
|
|
|
|
with IDs newer than `last_event_id`. Event IDs are guaranted to be increasing,
|
|
|
|
but they are not guaranteed to be consecutive.
|
|
|
|
|
|
|
|
#### Example response
|
|
|
|
|
|
|
|
A typical successful JSON response may look like:
|
|
|
|
|
2018-06-21 01:05:11 +02:00
|
|
|
{generate_code_example|/events:get|fixture(200)}
|
2018-06-01 21:41:50 +02:00
|
|
|
|
|
|
|
#### BAD_EVENT_QUEUE_ID errors
|
|
|
|
|
|
|
|
If the target event queue has been garbage collected, you'll get the
|
|
|
|
following error response:
|
|
|
|
|
2018-06-21 01:05:11 +02:00
|
|
|
{generate_code_example|/events:get|fixture(400)}
|
2018-06-01 21:41:50 +02:00
|
|
|
|
|
|
|
A compliant client will handle this error by re-initializing itself
|
|
|
|
(e.g. a Zulip webapp browser window will reload in this case).
|
|
|
|
|
2018-06-21 01:04:42 +02:00
|
|
|
See [the /register endpoint docs](/api/register-queue) for details on how to
|
|
|
|
handle these correctly.
|