From 3b8ee2a30f99c6de1d500880fa6ebf9084e26e09 Mon Sep 17 00:00:00 2001 From: Kartik Srivastava Date: Mon, 22 Jun 2020 04:01:56 +0530 Subject: [PATCH] js_examples: Migrate and test update_message example. --- templates/zerver/api/update-message.md | 18 +----------------- zerver/openapi/javascript_examples.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/templates/zerver/api/update-message.md b/templates/zerver/api/update-message.md index adb28534a6..f2c4d5c114 100644 --- a/templates/zerver/api/update-message.md +++ b/templates/zerver/api/update-message.md @@ -12,24 +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', -}; - -zulip(config).then((client) => { - // Update a message - const params = { - message_id: 131, - content: 'New Content', - } - - client.messages.update(params).then(console.log); -}); -``` +{generate_code_example(javascript)|/messages/{message_id}:patch|example} {tab|curl} diff --git a/zerver/openapi/javascript_examples.js b/zerver/openapi/javascript_examples.js index 65fa59ea1a..7ed3bed6bf 100644 --- a/zerver/openapi/javascript_examples.js +++ b/zerver/openapi/javascript_examples.js @@ -51,6 +51,7 @@ const ExamplesHandler = function () { await generate_validation_data(client, examples.add_subscriptions); 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); console.log(JSON.stringify(response_data)); return; @@ -302,4 +303,25 @@ add_example('update_message_flags', '/messages/flags:post', 200, async (client) return [result_1, result_2]; }); +add_example('update_message', '/messages/{message_id}:patch', 200, async (client) => { + const request = { + to: 'Denmark', + type: 'stream', + topic: 'Castle', + content: 'I come not, friends, to steal away your hearts.', + }; + const result = await client.messages.send(request); + const message_id = result.id; + + // {code_example|start} + // Update a message with the given "message_id" + const params = { + message_id: message_id, + content: 'New Content', + }; + + return await client.messages.update(params); + // {code_example|end} +}); + main();