mirror of https://github.com/zulip/zulip.git
js-api: Migrate and test send-message example.
This commit is contained in:
parent
203b722624
commit
1e4ad0bdfc
|
@ -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}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue