...
To make discussion within a context and every logged in user can be participated.
Architecture Diagram
...
Hierarchy of discussions
The below diagram explains the category & topics created for a Course & Batch. The same can be used for any other types like Group, Quiz, etc.
...
Angular | 8 or above |
Nodejs | 14 or above |
Nodebb | v1.18.6 |
Redis | 6.2.5 |
Info |
---|
Note: Install above things in your system. |
Nodebb
NodeBB is an open source project which can be forked on GitHub (Link). It have plugin support. We can create new plugins for our requirement and link to nodebb.
How to setup nodebb in local environment
Info |
---|
Note: Before staring nodebb setup in local. check redis is up and running. If not start redis first and do the setup. |
Step:1
Clone the nodebb repo
Code Block |
---|
git clone -b v1.18.x https://github.com/NodeBB/NodeBB.git nodebb |
Step:2
Navigate to nodebb folder and do setup of nodebb using below command
Code Block |
---|
./nodebb setup |
While running the setup, nodebb will ask below question for initial setup.
Code Block |
---|
>> URL used to access this NodeBB (http://localhost:4567) : Press Enter
>> Please enter a NodeBB secret (44abfc50-3d6a-4e6c-a258-9f551f9faa5a) : Press Enter
>> Would you like to submit anonymous plugin usage to nbbpm? (yes) : Press Enter
>> Which database to use (mongo) : redis
Now configuring redis database:
>> Host IP or address of your Redis instance (127.0.0.1) : Press Enter
>> Host port of your Redis instance (6379) : Press Enter
>> Password of your Redis database : Press Enter
>> Which database to use (0..n) (0) : 3 (redis db number)
Admin User details
>> Administrator username : admin
>> Administrator email address : admin@test.com
>> Password : Your password
>> Confirm Password : Your password |
Step:3
Now start the nodebb, Using below command.
Code Block |
---|
./nodebb start |
Step:4
Build the nodebb using the below command.
Code Block |
---|
./nodebb build |
Step:5
Open the browser with fallowing link http://localhost:4567
Use full commands
Code Block |
---|
./nodebb log -> To see the logs
./nodebb status -> To check is nodebb running or not
./nodebb activate plugin-name -> To activate the plugin
./nodebb reset -p plugin-name -> To reset/disable the plugin
./nodebb stop -> To stop nodebb |
Mandatory Plugins
We have built our own plugins based on our need. We need to enable those plugins.
nodebb-plugin-create-forum | Contains all custom api | |
nodebb-plugin-sunbird-oidc | User login api | https://github.com/Sunbird-Ed/nodebb-plugin-sunbird-oidc.git |
Activating Plugins
In this plugins, We added our own apis. Like User login, Enable discussion, read discussion context, disable discussion, user read based on sunbird id …. etc.
To activate plugin. Use below command.
a. Using repo as a npm module.
Code Block |
---|
npm install https://github.com/Sunbird-Ed/nodebb-plugin-sunbird-api.git
./nodebb activate nodebb-plugin-create-forum |
b. Using from local
clone the repo
https://github.com/Sunbird-Ed/nodebb-plugin-sunbird-api.git
`Execute command
npm install
Execute command
npm link
Go to nodebb terminal and execute command
npm link nodebb-plugin-create-forum
Execute command
./nodebb activate nodebb-plugin-create-forum
And execute command
./nodebb build
Info |
---|
Note: When you enable or disable any plugin, You have to rebuild and restart your nodebb. Then only the changes will reflects. |
Do the same thing for other plugin.
Write api plugin
This in an important plugin, By using this we can do all write operation in nodebb. Like create category/topic/post, updating topic/post, delete topic/post…..etc.
Install nodebb-plugin-write-api
Login to nodebb as a admin user.
Go to admin pannel.
Go to
EXTEND => PLUGINS => FIND PLUGINS
Search for
nodebb-plugin-write-api
Click on
Install
Rebuild and restart nodebb.
Reload the admin panel.
Go to
EXTEND => PLUGINS => INSTALLED
Search for
nodebb-plugin-write-api
Click on
Activate
Rebuild and restart nodebb.
What is Master token
To perform any write operations in nodebb we need write api plugin. And this plugin provides apis to do those write operations but If you want to use this apis we have to pass a master token (in request headers
as Authorization token) and nodebb user id(add _uid
as query param or with in request body ).
How to create master
Login to nodebb as a admin user.
Go to admin pannel.
Go to
PLUGINS => WRITE API
Left side panel you can see
MASTER TOKENS
Section.Click on
CREATE TOKEN
Refer this link also: Nodebb Plugins
Discussion Middleware Setup
Step:1
Clone the discussion middleware repo from https://github.com/Sunbird-Ed/discussions-middleware.git
Step:2
Execute npm install
command.
Step:3
add the environment variable in environmentHelper.js file.
Code Block |
---|
let localEnvVariables = {
NODEBB_SERVICE_URL: env.nodebb_service_url || 'http://localhost:4567',
Authorization: env.authorization_token || 'd8402b15-1d5f-4d84-9fae-595ef805f287', // Your local nodebb Master token
nodebb_api_slug: env.nodebb_api_slug || '/api'
} |
Info |
---|
Note: If your testing the DF-lib using demo application. You have to use user token instead of master token. Once we implemented DF-middleware cache then onwards no need to change the token. we can use master token itself. |
Step:4
Run the discussion middleware using the command npm run start
. Discussion-middleware will run on port 3002.
Discussion-UI setup along with demo application.
Step:1
Clone the discussion-ui repo from https://github.com/Sunbird-Ed/discussions-UI.git.
Step:2
Execute npm install
command.
Step:3
Change the host
in urlconfig.json
file. Add below url.
Code Block |
---|
host: 'http://localhost:3002' |
Step:4
Build the discussion-ui library using npm run build-lib
. This will generate a dist file along with assets. For every change in discussion-ui library you have to run build command.
Step:5
Run the demo application using the command npm run demo
. This is a simple angular application which is used to test df-library in local.
Info |
---|
Note: Demo application will run on port 4200. |
Nodebb api documentation
We can see all discussion forum api here : Discussion forum apis.
Discussion forum integration with any application
Discussion forum is library and can be attached to any application. Before integrating we have to verify following things
Application should maintain cache.
Discussion forum uid have to be stored in cache.
Uid need to attach for all discussion forum apis as a query param link
?_uid=${discussionForum_uid}
.
Add discussion for a context
We can attach discussion forum for any context like Groups/Courses/Batchs/Textbooks…etc.
Before attaching discussion forum we have to create one parent category and for context have one parent category. So that we can have all group context under one parent similarly for course, textbook.
You can see below image. Discussion forum for Groups
is a parent category and all group related discussion forums are under that category.
...
Schema
SbType | SbIdentifier | cid | Data |
---|---|---|---|
course | do_11317805943810457614592 | 5 | {JSON} |
batch | 01316730820300800028 | 6 | {JSON} |
group | 123475d2-c299-45f6-992e-a22d081431bd | 7 | {JSON} |
For example, We are adding discussion forum for group, For that we have to use below api.
Request
URL: https://staging.sunbirded.org/discussion/forum/v3/create
Payload:
Code Block |
---|
{
"category": {
"name": "General Discussion", // Name of the category
"pid": "30", // parent category id, under this category we are creating new categories
"description": "", // category description: Optional
"context": [
{
"type": "group", // type as a group
"identifier": "bc190919-f9a4-4e8a-a48b-2bba9c0b827f" // group Id
}
]
}
} |
Code Block |
---|
curl 'https://staging.sunbirded.org/discussion/forum/v3/create' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"' \
-H 'X-App-Id: staging.sunbird.portal' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' \
-H 'Content-Type: application/json' \
-H 'Access-Control-Allow-Origin: *' \
-H 'Accept: application/json' \
-H 'X-Device-Id: 23b82f7e68c9974eb17af148415a6067' \
-H 'X-Channel-Id: 0126796199493140480' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'Origin: https://staging.sunbirded.org' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://staging.sunbirded.org/my-groups/group-details/bc190919-f9a4-4e8a-a48b-2bba9c0b827f' \
-H 'Accept-Language: en-GB,en;q=0.9' \
-H 'Cookie: connect.sid=s%3AS3j18UnlsjcbY4_kbWjfCdO7iBvR0h_G.1dWXH%2Ba%2BUZ3zyFN4JnK2ucdU9mFqkRfmiPJrTgxulPU' \
--data-raw '{"category":{"name":"General Discussion","pid":"30","uid":"4","description":"","context":[{"type":"group","identifier":"bc190919-f9a4-4e8a-a48b-2bba9c0b827f"}]}}' \
--compressed |
Response
Code Block |
---|
{
"id": ".discussions.api.forum.v3.create",
"ver": "1.0",
"ets": 1642673148032,
"params": {
"resmsgid": "16ea8c5b-682c-4ac2-889e-d5896fc057fd",
"msgid": "",
"status": "Success"
},
"responseCode": "OK",
"result": {
"forums": [
{
"sbType": "group",
"sbIdentifier": "bc190919-f9a4-4e8a-a48b-2bba9c0b827f",
"newCid": 801, // New category created for group context
"cids": [801]
}
]
}
} |
In the above response we have newCid
that is the category id which is created for the group context that we pass in the request. So whet ever the discussions happened in the group are present in the discussion forum category.
...