@wix/wix-groups-feed-client
TypeScript icon, indicating that this package has built-in type declarations

1.15.0 • Public • Published

Client library for Wix Groups Feed API to create, read, update, and delete feed items in Wix Groups.

Usage

import {WixGroupsFeedService} from 'wix-groups-feed-client';

const authorization = 'value-auth-token-here'
const siteId = 'site-id-here'
const client = new WixGroupsFeedService(authorization, siteId);

try {
  const posts = await client.listFeedItems("<group_id>");
} catch (e) {
  console.log('Error with code: ', e.errorCode);
}

Authorization

The client library requires an authorization header to be passed to the constructor. Check Wix Api Keys and Api Keys support article which explains how to create it.

Important: The API token should be created with Wix Groups site permissions enabled (in Wix, you may choose apps and permissions for the token; make sure you select Wix Communities or Wix Groups).

The token should look like:

IST.eyJraWQiOiJQb3pIX2FDMiIsImFsZyI6IlJTMjU2In0.eyJkYXRh....RERER

Debug mode

To enable debug mode, specify the debugMode option in the constructor:

const client = new WixGroupsFeedService(authorization, siteId, {debugMode: true});

In a debug mode, the client library will log all requests and responses to the console.

API Overview

Feed Items

Each feed item could be a post about some group activity (created automatically by the system) or a Rich Content post made by a user (paid or not).

FeedItem object has the following fields:

  • feedItemId - the id of the feed item
  • entity - the entity of the feed item (returned only for user-created posts).
    • The format of user-created posts could be plain text, draft-js (deprecated), and a new format called RICH_CONTENT. You can read more about the new format on Ricos site.
  • activity - describes the activity of the feed item (returned only for activity posts). Examples of activity posts: group description has been changed, group name has been changed, group member has been added, etc.
  • preview - a preview for the paid posts. Returned if the user has no permission to view the full post.
  • pin - describes the pin status of the feed item. The pin object has the following fields:
    • pinnedBy - user who pinned the post
    • since - the date when the post was pinned
  • permissions - describes the current user's permissions on the feed item. The permissions object has the following fields:
    • canViewFullPost - user can view the full post
    • ``canAssignTopic` - user can assign a topic to the post
    • canUnassignTopic - user can unassign a topic from the post
    • canUpdate - user can update the post
    • canDelete - user can delete the post
    • canShare - user can share the post (always set to true based on current implementation)
    • canAddComment - user can add a comment to the post
    • canReact - user can add a reaction to the post
    • canPin - user can pin the post
  • createdBy - the id of the user who created the feed item
  • createdAt - the date when the feed item was created
  • requesterContext - describes the context of the user who requested the feed item. The requester context object has the following fields:
    • subscribed - whether the user is subscribed to the feed item

Additional Permissions

For list/query methods, the response contains a FeedPermissions object that describes actions for all posts or actions that are not specific to a single post. It has the following fields:

  • canViewPosts - user can view the posts at all
  • canCreatePosts - user can create a post
  • canCreatePaidPosts - user can create a paid post
  • canPinPost - user can pin a posts
  • canCreateTopic - user can create a new topic
  • canFollowPosts - user can follow posts

API Reference

Examples below show how to use the client library from Velo.

It's also possible to use the client library in any other environment that supports JavaScript.

createFeedItem(groupId: string)

Creates a feed item in the group feed.

Request example:

In example below we create a feed item with a DraftJS content.

export const createFeedItem = webMethod(
  Permissions.Anyone, 
  async (groupId) => {
    try {
      const content = {
        "blocks": [{
            "key": "au2sn",
            "text": "<TEXT>",
            "type": "unstyled",
            "depth": 0,
            "inlineStyleRanges": [{
                "offset": 0,
                "length": 4,
                "style": "BOLD"
            }],
            "entityRanges": [],
            "data": {}
        }],
        "entityMap": {},
        "documentStyle": {},
        "VERSION": "9.14.6",
        "ID": "94ca0800-9063-4d5b-9746-92501a34859a"
    }

      const post = await client.createFeedItem(groupId, {
        body: {
          contentType: 'DRAFTJS',
          content: JSON.stringify(content)
        }
      });
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);

listFeedItems(groupId: string)

Get a list of feed items by group id.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const listFeedItems = webMethod(
  Permissions.Anyone, // make sure to update permissions if needed
  async (groupId) => {
    try {
      const posts = await client.listFeedItems(groupId);
      return posts;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);
Response example:
{
   "feedItems":[
      {
         "feedItemId":"c80bd29d-91ea-4253-a839-79de53469f2e",
         "entity":{
            "body":{
               "contentType":"DRAFTJS",
               "content":"{\"blocks\":[{\"key\":\"1\",\"text\":\"Welcome to our group My Site Group! A space for us to connect and share with each other. Start by posting your thoughts, sharing media, or creating a poll.\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[{\"offset\":21,\"length\":16,\"style\":\"BOLD\"}],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}"
            }
         },
         "createdBy":"fc2258d5-a366-4b9c-a93f-1f344f14493f",
         "createdAt":"2024-03-13T12:25:30.822232258Z",
         "requesterContext":{
            "subscribed":false
         }
         "permissions":{
            "canViewFullPost":true,
            "canAssignTopic":false,
            "canUnassignTopic":false,
            "canUpdate":false,
            "canDelete":false,
            "canShare":true,
            "canAddComment":false,
            "canReact":false,
            "canPin":false
         }
      }
   ],
   "permissions":{
      "canViewPosts":true,
      "canCreatePosts":false,
      "canPinPosts":false,
      "canCreateTopic":false,
      "canFollowPosts":false,
      "canCreatePaidPosts":false
   }
}

getFeedItem(groupId: string, feedItemId: string)

Returns a feed item by its id.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const getFeeditem = webMethod(
    Permissions.Anyone, // make sure to update permissions if needed
  async (groupId, feedItemId) => {
    try {
      const post = await client.getFeedItem(groupId, feedItemId);
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);
Response example:
{
  "feedItemId":"c80bd29d-91ea-4253-a839-79de53469f2e",
  "entity": {...},
  ...
}

deleteFeedItem(groupId: string, feedItemId: string)

Deletes a feed item by its id.

Returns a deleted feed item.

Request example:
const authorization = '<value-auth-token-here>'
const client = new WixGroupsFeedService(authorization, '<site-id-here>', {debugMode: false});

export const deleteFeedItem = webMethod(
  Permissions.Anyone, // make sure to update permissions if needed
  async (groupId, feedItemId) => {
    try {
      const post = await client.deleteFeedItem(groupId, feedItemId);
      return post; // returns deleted post
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);

updateFeedItem(groupId: string, feedItemId: string, entity: FeedItemEntity)

Updates a feed item by its id. It allows you to update the content of the post.

Returns an updated feed item.

Request example:
export const updateFeedItem = webMethod(
  Permissions.Anyone, 
  async (groupId, feedItemId) => {
    try {
      const content = {
        "blocks": [{
            "key": "au2sn",
            "text": "<UPDATED_TEXt>",
            "type": "unstyled",
            "depth": 0,
            "inlineStyleRanges": [{
                "offset": 0,
                "length": 4,
                "style": "BOLD"
            }],
            "entityRanges": [],
            "data": {}
        }],
        "entityMap": {},
        "documentStyle": {},
        "VERSION": "9.14.6",
        "ID": "94ca0800-9063-4d5b-9746-92501a34859a"
      }

      const post = await client.updateFeedItem(groupId, feedItemId,  {
        body: {
          contentType: 'DRAFTJS',
          content: JSON.stringify(content)
        }
      });
      return post;
    } catch (e) {
      console.log('Error with code: ', e);
    } 
  }
);

/@wix/wix-groups-feed-client/

    Package Sidebar

    Install

    npm i @wix/wix-groups-feed-client

    Weekly Downloads

    13

    Version

    1.15.0

    License

    UNLICENSED

    Unpacked Size

    67 kB

    Total Files

    34

    Last publish

    Collaborators

    • yoav
    • wix-ci
    • shahata
    • wixnpm
    • wix-ambassador
    • netanelgilad
    • wix-ci-publisher
    • wix-bi-publisher
    • galil-team
    • lxgreen
    • ariki
    • liorgwix
    • usability-sessions
    • yurynix
    • oferb-wix
    • domasmak
    • mayaco
    • amitde007
    • tombenezra
    • itaytay
    • haimbrum-wix
    • youngshinobi
    • varzager
    • benblayer-wix
    • itai.benda
    • arielh
    • falconci
    • roir-wix
    • dorchaouat