Get events from an event queue
GET https://zulip.dioco.io/api/v1/events
This endpoint allows you to receive new events from
a registered event queue.
Usage examples
#!/usr/bin/env python
import sys
import zulip
# Pass the path to your zuliprc file here.
client = zulip.Client(config_file="~/zuliprc")
# 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
# parameters, 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.
More examples and documentation can be found here.
const Zulip = require('zulip-js');
// Pass the path to your zuliprc file here.
const config = { zuliprc: 'zuliprc' };
Zulip(config).then(async (client) => {
// Retrieve events from a queue with given "queue_id"
const eventParams = {
queue_id: queue_id,
last_event_id: -1,
};
return await client.events.retrieve(eventParams);
}).then(console.log).catch(console.err);
curl -sSX GET -G https://zulip.dioco.io/api/v1/events \
-u BOT_EMAIL_ADDRESS:BOT_API_KEY \
-d 'queue_id=1375801870:2942' \
-d 'last_event_id=-1'
Parameters
queue_id required
Example: 1375801870:2942
The ID of an event queue that was previously registered via POST
/api/v1/register
(see Register a queue).
last_event_id optional
Example: -1
dont_block optional
Example: True
Set to true
if the client is requesting a nonblocking reply. If not
specified, the request will block until either a new event is available
or a few minutes have passed, in which case the server will send the
client a heartbeat event.
Defaults to false
.
Note: The parameters documented above are optional in the sense that
even if you haven't registered a queue by explicitly requesting the
https://zulip.dioco.io/api/v1/register
endpoint, you could pass the parameters for
the https://zulip.dioco.io/api/v1/register
endpoint to this
endpoint and a queue would be registered in the absence of a queue_id
.
Response
Return values
-
events
: An array of event
objects (possibly zero-length if dont_block
is
set) with IDs newer than last_event_id
. Event IDs are
guaranteed to be increasing, but they are not guaranteed to be
consecutive.
-
queue_id
: The ID of the registered queue.
Example response
A typical successful JSON response may look like:
{
"events": [
{
"id": 0,
"message": {
"avatar_url": "https://url/for/othello-bots/avatar",
"client": "website",
"content": "I come not, friends, to steal away your hearts.",
"content_type": "text/x-markdown",
"display_recipient": "Denmark",
"id": 12345678,
"recipient_id": 12314,
"sender_email": "othello-bot@example.com",
"sender_full_name": "Othello Bot",
"sender_id": 13215,
"sender_realm_str": "example",
"timestamp": 1375978403,
"topic": "Castle",
"topic_links": [],
"type": "stream"
},
"type": "message"
},
{
"id": 1,
"message": {
"avatar_url": "https://url/for/othello-bots/avatar",
"client": "website",
"content": "With mirth and laughter let old wrinkles come.",
"content_type": "text/x-markdown",
"display_recipient": [
{
"email": "hamlet@example.com",
"full_name": "Hamlet of Denmark",
"id": 31572
}
],
"id": 12345679,
"recipient_id": 18391,
"sender_email": "othello-bot@example.com",
"sender_full_name": "Othello Bot",
"sender_id": 13215,
"sender_realm_str": "example",
"subject": "",
"timestamp": 1375978404,
"topic_links": [],
"type": "private"
},
"type": "message"
}
],
"msg": "",
"queue_id": "1375801870:2942",
"result": "success"
}
BAD_EVENT_QUEUE_ID errors
If the target event queue has been garbage collected, you'll get the
following error response:
{
"code": "BAD_EVENT_QUEUE_ID",
"msg": "Bad event queue id: 1518820930:1",
"queue_id": "1518820930:1",
"result": "error"
}
A compliant client will handle this error by re-initializing itself
(e.g. a Zulip webapp browser window will reload in this case).
See the /register endpoint docs for details on how to
handle these correctly.