Unofficial, Discourse Api wrapper for Node
This package is a work in progress and a large number of features are still under development. If you need to add functionality, please pull request to add a new method, or use api._request
to request any API endpoint.
β οΈIMPORTANT: Regarding version numbers, any version before releasing version 1.0.0 SHOULD NOT be considered a stable version and we MAY change the API and cause incompatibilities. When there is an incompatible API, we will increment the minor version. When a new API is covered, we will increment the patch version.
β: Not started yet
π©: Work in progress
β
: Completed
API | Progress |
---|---|
Backups | β |
Badges | β |
Categories | β |
Groups | β |
Invites | β |
Notifications | β |
Posts | β |
Topics | π© |
Private Messages | β |
Search | β |
Site | β |
Tags | β |
Uploads | π© |
Users | π© |
Admin | β |
Chat | π© |
Webhook | π© |
npm install node-discourse-api
const { DiscourseApi } = require("node-discourse-api");
const api = new DiscourseApi("https://discourse.example.com");
// API configured by Discourse administrator. You can also leave it unset and have the API read only the public content of your forum.
api.options.api_username = "API_USERNAME";
api.options.api_key = "API_KEY";
// Create a new topic, then print it to console
api
.createTopicPostPM({
raw: "This is a post from node-discourse-api!!!",
title: "Hello world!!!",
})
.then((post) => {
console.log(post);
});
// Post a reply
api.createTopicPostPM({
raw: "This is a reply post from node-discourse-api!!!",
topic_id: 1,
});
// Reply to a post
api.createTopicPostPM({
raw: "This is a reply of reply from node-discourse-api!!!",
topic_id: 1,
reply_to_post_number: 2,
});
// Handling errors
api
.createTopicPostPM({
raw: "This reply cannot be sent",
topic_id: -123,
})
.catch((err) => {
console.log("Catched a error");
console.error(err);
});
// Send a message in channel 2. Probably, it's #general
api.chat.sendMessage(2, "hello, world!");
const { DiscourseApi } = require("node-discourse-api");
const api = new DiscourseApi("https://discourse.example.com");
const generated = api.generateUserApiKeySync();
console.log(
"Please visit the following URL authorization and paste the generated key in the console:",
);
console.log(generated.url);
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
readline.question(`Paste key: `, (key) => {
const decrypted = api.decryptUserApiKey(generated.private_key, key);
console.log(decrypted);
api.options.user_api_key = decrypted.key;
api.createTopicPostPM({
raw: "This is a post from node-discourse-api!!!",
title: "Hello world!!!",
});
readline.close();
});
For more examples, see the API documentation
We have set up some git hooks to help maintain code quality. If you would like to contribute to this project, please initialize in this order
git clone https://github.com/Lhcfl/node-discourse-api
cd node-discourse-api
yarn install
yarn devprepare
Test code:
yarn test
autofix:
yarn autofix
Generated using TypeDoc