diff --git a/templates/zerver/api/send-message.md b/templates/zerver/api/send-message.md index 0c425c0cf9..d47e6d0915 100644 --- a/templates/zerver/api/send-message.md +++ b/templates/zerver/api/send-message.md @@ -12,41 +12,8 @@ {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', -}; - -// Send a stream message -zulip(config).then((client) => { - // Send a message - const params = { - to: 'Denmark', - type: 'stream', - subject: 'Castle', - content: 'I come not, friends, to steal away your hearts.' - } - - client.messages.send(params).then(console.log); -}); - -// Send a private message -zulip(config).then((client) => { - // Send a private message - const user_id = 9; - const params = { - to: [user_id], - type: 'private', - content: 'With mirth and laughter let old wrinkles come.', - } - - client.messages.send(params).then(console.log); -}); - -``` +{generate_code_example(javascript)|/messages:post|example} {tab|curl} diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js index 13a7d13572..83debf483a 100644 --- a/zerver/openapi/javascript_examples.js +++ b/zerver/openapi/javascript_examples.js @@ -62,6 +62,31 @@ const {main, add_example} = ExamplesHandler(); // Declare all the examples below. +add_example('send_message', '/messages:post', 200, async (client) => { + // {code_example|start} + // Send a stream message + let params = { + to: 'Denmark', + type: 'stream', + topic: 'Castle', + content: 'I come not, friends, to steal away your hearts.', + }; + const result_1 = await client.messages.send(params); + // {code_example|end} + + // {code_example|start} + // Send a private message + const user_id = 9; + params = { + to: [user_id], + type: 'private', + content: 'With mirth and laughter let old wrinkles come.', + }; + const result_2 = await client.messages.send(params); + // {code_example|end} + return [result_1, result_2]; +}); + add_example('create_user', '/users:post', 200, async (client) => { // {code_example|start} const params = {