Skip to main content

How to create topics and add child-topics in LikeMinds Feed?

Creating Parent and Child topics.

This document will guide you to create topics in LikeMinds Feed SDK as well as adding child-topics to it. This sort of use-case comes handy where you want to serialize your posts and link them to make a relational order.

Step 1 - Get Access Token for a Admin

  1. Get the User Unique Id of the Owner Bot from the LikeMinds Admin Dashboard. Navigate to Members section and Get the Unique Id of the Owner Bot for further use. Save the the Unique ID for futures usages for calling APIs.
  2. Now, you need to obtain the accessToken for Owner Bot. This token is necessary for authenticating API calls. Call the POST sdk/initiate API to login with Owner Bot ID credentials. You can fetch the user unique id and API key from the dashboard and add in the respective placeholder below.
curl --location 'https://auth.likeminds.community/sdk/initiate' \
--header 'x-api-key: {LIKEMINDS_API_KEY}' \
--header 'x-sdk-source: chat' \
--header 'x-api-version: 1' \
--header 'Content-Type: application/json' \
--data '{
"uuid": "{UUID_OF_OWNER_BOT_FROM_DASHBOARD}",
}'

When you receive a 200 response in the response body data.access_token will be used as Authorization token in the following APIs.

Step 2- Create a Parent Topic

You will have to create a regular topic which will serve as a parent to all the subsequent topics you will make. You can make a topic through a curl request.

curl --location 'https://auth.likeminds.community/feed/topic' \
--header 'Authorization: {{auth_token}}' \
--header 'x-platform-type: dashboard' \
--header 'Content-Type: application/json' \
--data '{
"topics": [
{
"name": "Topic #1"
},
{
"name": "Topic #2"
},
{
"name": "Topic #3"
}
]
}'

Step 2 - Add Child Topics to Parent Topics

Now you will have to create child-topics for the above created parent topic. To do so copy the _id for the parent topic, you will put this in the parent-topic-id key of the subsequent topic object.

curl --location 'https://auth.likeminds.community/feed/topic' \
--header 'Authorization: {{auth_token}}' \
--header 'x-platform-type: dashboard' \
--header 'Content-Type: application/json' \
--data '{
"topics": [
{
"name": "Child Topic #1"
"parent_id":"{{topic_id of Topic #1}}"
},
{
"name": "Child Topic #2"
"parent_id":"{{topic_id of Topic #1}}"
},
{
"name": "Child Topic #3"
"parent_id":"{{topic_id of Topic #1}}"
}
]
}'

Fetching Topics using data layer

Fetch Parent Topics

You can get the parent-topics, by using the function getTopics() of your LMFeedClient instance.

Below snippet explains how you can achieve this.

import { GetTopicsRequest } from "@likeminds.community/feed-js";

async function fetchTopics() {
try {
const response = await lmFeedclient?.getTopics(
GetTopicsRequest.builder()
.setPage(1)
.setPageSize(10)
.isEnabled(true)
.build()
);
// parse the response as needed
} catch {
// parse the error as needed
}
}

The above response will have all the parent topics present in LikeMinds Feed. For detailed information about getTopics(), click here

Fetch Child Topics

You can get the child-topics for any parent-topic, Provided you have the id of the topic, by using the function getTopics() of your LMFeedClient instance.

info

You can get the parent id of any topic, inside the topic object itself.

Below snippet explains how you can achieve this.

import { GetTopicsRequest } from "@likeminds.community/feed-js";

async function fetchTopics() {
try {
// List of your parent Ids
const parentIdsList = ["ADD-TO-YOUR-LIST-OF-PARENT-IDS"];

const getTopicsCall = await lmFeedclient?.getTopics(
GetTopicsRequest.builder()
.setPage(1)
.isEnabled(true)
.setPageSize(10)
.setParentIds(parentIdsList)
.build()
);
// parse the response as needed
} catch {
// parse the error as needed
}
}

The above response will have all the parent topics present in LikeMinds Feed. For detailed information about getTopics(), click here

How to get posts of child topic and parent topic in a single feed?

While rendering your feed, you can select specific topics and get feed only related to those topics. You can do so by passing the ids of desired topics to the followedTopics prop of LMFeedUniversalFeed component. Additionally, you can also select the desired topics along with it's parent-topic. Below steps explains on how you can do so.

Step 1: Create a custom LMFeedUniversalFeed wrapper component

import { LMFeedUniversalFeed } from "@likeminds.community/likeminds-feed-reactjs";

interface CustomLMFeedUniversalFeedProps {
lmFeedClient: LMFeedClient;
}

export function CustomLMFeedUniversalFeed({
lmFeedClient,
}: CustomLMFeedUniversalFeedProps) {
const [selectedTopics, setSelectedTopics] = useState([]);
useEffect(() => {
const childTopic = "YOUR-CHILD-TOPIC-ID";
const parentTopic = `#$ONLY$#${childTopic.parentTopicId}`;
const topicList = [childTopic, parentTopic];
setSelectedTopics(topicList);
}, []);

return <LMFeedUniversalFeed followedTopics={selectedTopics} />;
}

Step 2: Pass the custom wrapper to LMSocialFeed

Now you need to pass CustomUniversalFeed to LMSocialFeed as a custom component.

<LMSocialFeed
// Other props
CustomComponents={{
CustomUniversalFeed: <CustomUniversalFeed />,
}}
></LMSocialFeed>
info

To get the list of all the required props, check out this guide.