Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js_examples: Migrate and test get_events example.

Kartik Srivastava87787efa814d
diff --git a/templates/zerver/api/get-events.md b/templates/zerver/api/get-events.md
index 88757d2fc01..7c4b6416771 100644
--- a/templates/zerver/api/get-events.md
+++ b/templates/zerver/api/get-events.md
@@ -31,31 +31,8 @@ a queue for you.
{tab|js}
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
-```js
-const zulip = require('zulip-js');
-
-// Pass the path to your zuliprc file here.
-const config = {
- zuliprc: 'zuliprc',
-};
-
-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);
- });
-});
-```
+
+{generate_code_example(javascript)|/events:get|example}
{tab|curl}
diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js
index 7ed3bed6bf4..a1d02292b75 100644
--- a/zerver/openapi/javascript_examples.js
+++ b/zerver/openapi/javascript_examples.js
@@ -52,6 +52,7 @@ const ExamplesHandler = function () {
await generate_validation_data(client, examples.remove_subscriptions);
await generate_validation_data(client, examples.update_message_flags);
await generate_validation_data(client, examples.update_message);
+ await generate_validation_data(client, examples.get_events);
console.log(JSON.stringify(response_data));
return;
@@ -324,4 +325,32 @@ add_example('update_message', '/messages/{message_id}:patch', 200, async (client
// {code_example|end}
});
+add_example('get_events', '/events:get', 200, async (client) => {
+ // Register queue to receive messages for user.
+ const queueParams = {
+ event_types: ['message'],
+ };
+ const res = await client.queues.register(queueParams);
+ const queue_id = res.queue_id;
+ // For setup, we send a message to ensure there are events in the
+ // queue; this lets the automated tests complete quickly.
+ const params = {
+ to: 'social',
+ type: 'stream',
+ topic: 'Castle',
+ content: 'I come not, friends, to steal away your hearts.',
+ };
+ client.messages.send(params);
+
+ // {code_example|start}
+ // 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);
+ // {code_example|end}
+});
+
main();
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 0a4ff23bc79..ae0c56068d6 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -158,8 +158,13 @@ paths:
items:
type: object
additionalProperties: false
+ queue_id:
+ type: string
+ description: |
+ The ID of the registered queue.
- example:
{
+ "queue_id": "1375801870:2942",
"events": [
{
"id": 0,