Create Post
Allows users to compose and publish new posts within the application, facilitating content creation and user-generated interactions.
Steps to create a post
- Use the
addPost()
function provided by thelmFeedClient
object created earlier. - Create an instance of
AddPostRequest
, as shown in the snippet and pass it to the above method. - Use the response as per your requirement
try {
const attachmentArr = [];
const topicIds = [];
const isAnonymous = true;
const addPostRequest = AddPostRequest.builder()
.setHeading("Post heading")
.setText("Post content")
.setAttachments(attachmentArr)
.setTopicIds(topicIds)
.setTempId("TEMP_ID")
.setIsAnonymous(isAnonymous ?? false)
.build();
const response = await lmFeedClient.addPost(addPostRequest);
// Use the response as per your requirement.
} catch (error) {
// Use the error as per your requirement.
}
Additional Features
Tag a User
To tag a user, use the getTaggingList() function to fetch the list of users that can be tagged, and use the format <<[user.name]|route://user_profile/[user.sdkClientInfo.uuid]>>
to embed it inside the text of the post.
Decode URL
To decode a URL, use the decodeUrl() function to decode a URL and get its OGTags. Use those to add an attachment of type 4.
Add a Topic
Topics are keywords related to a post, they can be considered having the same use case as hashtags. You can add a topic to the post by sending the topicIds
list in the AddPostRequest
with the topics you have fetched using the getTopics().
Models
AddPostRequest
Variable | Type | Description | Optional |
---|---|---|---|
text | string | Text content of the post. | ✔️ |
attachments | Attachment | Attachments to be uploaded. | ✔️ |
heading | string | Heading of the post. | ✔️ |
tempId | string | Temporary ID of post. | ✔️ |
topicIds | string[] | List of topics user want to add in the post. | ✔️ |
onBehalfOfUUID | string | UUID of the user on whose behalf the post is created. | ✔️ |
isAnonymous | boolean | Indicates if the post should be anonymous. |
Note You cannot create an empty post. Send data in at least one of these keys: text, heading, or attachments
AddPostResponse
Variable | Type | Description | Optional |
---|---|---|---|
post | Post | Object of the created post. | ✔️ |
users | Record<string,User> | Map of user unique id to user object. | |
topics | Record<string,Topic> | Map of topic id to topic object. | ✔️ |
widget | Widget | Widget data for the post. |