Discussions operations

Get the configuration for all platform interactions

Discussions operations are responsible for communicating with Discussions API.

The namespace is of course called discussions. All methods return promises. The general design of the namespace follows this pattern unless stated otherwise:

πŸ“˜

General call:

sdk.discussions
  .someMethod()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

The responses are comprised of different objects you can find here.

General operations

Get config

Method: getConfig()

This method returns discussions configuration.

πŸ“˜

Example call:

sdk.discussions
  .getConfig()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   enabled: true,
   clientId: "productiontesting1",
   automaticModeration: {
      enabled: false,
      moderateLinks: false,
      linksWhitelist: null,
      moderatorProfileId: "IjvDaChth0Mf4yhMszTO5Vr7ZbN2",
      dictionary: {
         reason: "BAD_LANGUAGE",
         words: [
            "moron",
            "imbacile"
         ]
      }
   }
}

Discussion related operations

Get list of discussions

Method: getAll(filters?, disableCache?)

Method returns list of discussions.

Filters options:

  • discussionIds: string[]. A list of discussion ids to filter out. Maximum number of ids is 10.
  • label: string. Every discussion has a label set by the client.
  • fromDate: string. From date of the creation of discussion. The date should be in the following format: YYYY-MM-DDThh:mm:ssZ
  • toDate: string. To date of the creation of discussion. The date should be in the following format: YYYY-MM-DDThh:mm:ssZ
  • fromCount: string. The minimum number of posts count for discussion.
  • toCount: string. The maximum number of posts count for discussion.
  • sort: DiscussionsSortTypes. Union type. Available values are: CREATED_AT_ASC, CREATED_AT_DESC, POSTS_COUNT_ASC, POSTS_COUNT_DESC
    • CREATED_AT_ASC - Discussions will be sort out by created at field in ascending order.
    • CREATED_AT_DESC - Discussions will be sort out by created at field in descending order.
    • POSTS_COUNT_ASC - Discussions will be sort out by their posts count in ascending order.
    • POSTS_COUNT_DESC - Discussions will be sort out by their posts count in descending order
  • limit: number . How many discussions will be returned in list.
  • startAfter: string . The ID after which the discussions should be listed. To be used in the context of infinite scroll/pagination.

API limitations:

  1. Per request, only one of the fromDate, toDate, fromCount, toCount filters can be used
  2. Per request, together can't be used fromDate and toDate with sort with value POSTS_COUNT_ASC or POSTS_COUNT_DESC
  3. Per request, together can't be used fromCount and toCount with sort with value CREATED_AT_ASC or CREATED_AT_DESC

If no value is provided for filters, then no filters will be aplied.

The response from API is cached for 1 hour. With disableCache argument you can avoid cached response.
If no value is provided it will be set to false by default.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

sdk.discussions
  .getAll()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
  meta: {
    pagination: {
      nextPageStartsAfter: "discussionId",
      itemsPerPage: 1,
    },
  },
  data: [
    {
      id: "discussionId",
      label: "label",
      discussionType: "COMMENT_SECTION", // Can be PRIVATE_LEAGUE
      moderationType: "STAFF", // Can be USER
      postsCount: 3,
      pinnedPosts: null,
      lastPostId: "6R9kQ0pSWneerzzDH0QCwP",
      context: {
        content: null,
        tags: [
          {
            id: "fb:c:3",
            type: "competition",
            source: "FOOTBALL",
          },
          {
            id: "fb:p:4208559",
            type: "player",
            source: "FOOTBALL",
          },
          {
            id: "fb:t:889",
            type: "team",
            source: "FOOTBALL",
          },
        ],
        campaign: null,
      },
      createdAt: "2023-12-11T07:24:51Z",
      updatedAt: "2023-12-12T13:36:37Z",
    },
  ],
}

Get discussion by ID

Method: getById(discussionId)

Method returns discussion by ID.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

sdk.discussions
  .getById("discussionId")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   id: "discussionId",
   label: "label",
   discussionType: "COMMENT_SECTION", // Can be PRIVATE_LEAGUE
   moderationType: "STAFF", // Can be USER
   postsCount: 3,
   pinnedPosts: null,
   lastPostId: "6R9kQ0pSWneerzzDH0QCwP",
   context: {
      content: null,
      tags: [
         {
            id: "fb:c:3",
            type: "competition",
            source: "FOOTBALL"
         },
         {
            id: "fb:p:4208559",
            type: "player",
            source: "FOOTBALL"
         },
         {
            id: "fb:t:889",
            type: "team",
            source: "FOOTBALL"
         }
      ],
      campaign: null
   },
   createdAt: "2023-12-11T07:24:51Z",
   updatedAt: "2023-12-12T13:36:37Z"
}

Posts for specific discussion operations

Create post for specific discussion

Method: createPost(discussionId, body)

Method returns the newly created post for the specified discussion.

N.B. When creating a new post, the discussion's context will be updated from post's context!!!

N.B.2 This method is private and it requires JWT.

πŸ“˜

Example call:

const body = {
  content: "New awesome post!",
  replyId: "postId", // can be null
  context: {
    content: {
      id: "id",
      label: "label",
      type: "type"
    }, // Can be null
    tags: [
      {
        id: "entityId",
        type: "entityType",
        source: "entitySource"
      }
    ],
    campaign: {
      id: "id",
      label: "label"
    } // Can be null
  }
};

sdk.discussions
  .createPost("discussionId", body)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
  id: "6R9kQ0pSWneerzzDH0QCwP",
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  discussionId: "discussionId",
  content: "New awesome post!",
  repliesCount: 0,
  replyId: "postId",
  reactions: [],
  reactionsCount: 0,
  reports: [],
  reportsCount: 0,
  versions: [],
  privatePost: false,
  deleted: false,
  deletedAt: null,
  deletedBy: null,
  moderated: false,
  moderatedAt: null,
  moderatedBy: null,
  moderatedReason: null,
  createdAt: "2023-12-11T11:58:47Z",
  updatedAt: "2023-12-11T11:58:47Z",
}

Get all posts for specific discussion

Method: getPosts(discussionId, filters?)

Method returns all posts for the specified discussion.

Filters options:

  • skipDeleted: boolean. By default Discussions API returns all posts who are not deleted. When set to false, the deleted posts for discussion will be returned.
  • sort: DiscussionsSortTypes. Union type. Available values are: OLDEST, LATEST, INTERACTED, POPULAR
    • OLDEST - Posts will be sort out by created at field in ascending order.
    • LATEST - Posts will be sort out by created at field in descending order.
    • INTERACTED - Posts will be sort out by reactions count.
    • POPULAR - Posts will be sort out by positive reactions count. Positive reactions are: LIKE, LOVE, LAUGH and CARE
  • limit: number . How many posts will be returned in list.
  • startAfter: string . The ID after which the posts should be listed. To be used in the context of infinite scroll/pagination.

If no value is provided for filters, then no filters will be aplied.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

sdk.discussions
  .getPosts("discussionId")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  startAfter: "postId",
  skipDeleted: false,
  sort: "POPULAR",
};

sdk.discussions
  .getPosts("discussionId", filters)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    totalItems: 1,
    nextPageStartsAfter: "postId",
    lastCommentCreateTimestamp: "2023-12-11T11:58:47Z"
  },
  data: [
    {
      id: "postId",
      userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
      userModel: {
        id: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
        name: "Viktor Yordanov",
        avatar: "http://localhost/wp-content/uploads/2023/08/Fyz851FXsAEv824.0-square-3.jpg",
        gender: "male",
        country: {
          id: "profile:cnt:23",
          name: "Bulgaria",
          assets: {
            flag: "https://profile.fansunitedassets.com/country/3a92ffe9-8e19-11eb-b60d-42010a84003b.png",
          },
        },
        birthDate: "1996-11-20",
        followingCount: 3,
        followersCount: 2,
        nickname: null,
      },
      discussionId: "discussionId",
      content: "New awesome post!",
      repliesCount: 0,
      replyId: "postId",
      reactions: [],
      reactionsCount: 0,
      reports: [],
      reportsCount: 0,
      versions: [],
      privatePost: false,
      deleted: false,
      deletedAt: null,
      deletedBy: null,
      moderated: false,
      moderatedAt: null,
      moderatedBy: null,
      moderatedReason: null,
      createdAt: "2023-12-11T11:58:47Z",
      updatedAt: "2023-12-11T12:58:47Z",
    }
  ]
}

Posts related operations

Update post

Method: updatePost(postId, content)

Method updates post's content.

N.B. This method is private and it requires JWT.

πŸ“˜

Example call:

sdk.discussions
  .updatePost("postId", "Content is updated!")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  id: "postId",
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  discussionId: "discussionId",
  content: "Content is updated!",
  repliesCount: 0,
  replyId: "postId",
  reactions: [],
  reactionsCount: 0,
  reports: [],
  reportsCount: 0,
  versions: [
    {
      content: "New awesome post!",
      updateAt: "2023-12-11T11:58:47Z"
    }
  ],
  privatePost: false,
  deleted: false,
  deletedAt: null,
  deletedBy: null,
  moderated: false,
  moderatedAt: null,
  moderatedBy: null,
  moderatedReason: null,
  createdAt: "2023-12-11T11:58:47Z",
  updatedAt: "2023-12-11T12:58:47Z"
}

Delete post

Method: deletePost(postId)

Method deletes post.

N.B. This method is private and it requires JWT.

πŸ“˜

Example call:

sdk.discussions
  .deletePost("postId")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

true

Get post by ID

Method: getPostById(postId)

Method returns post by ID.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

sdk.discussions
  .getPostById("postId")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });
{
  id: "postId",
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  userModel: {
    id: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
    name: "Viktor Yordanov",
    avatar: "http://localhost/wp-content/uploads/2023/08/Fyz851FXsAEv824.0-square-3.jpg",
    gender: "male",
    country: {
      id: "profile:cnt:23",
      name: "Bulgaria",
      assets: {
        flag: "https://profile.fansunitedassets.com/country/3a92ffe9-8e19-11eb-b60d-42010a84003b.png",
      },
    },
    birthDate: "1996-11-20",
    followingCount: 3,
    followersCount: 2,
    nickname: null,
  },
  discussionId: "discussionId",
  content: "Content is updated!",
  repliesCount: 0,
  replyId: "postId",
  reactions: [],
  reactionsCount: 0,
  reports: [],
  reportsCount: 0,
  versions: [
    {
      content: "New awesome post!",
      updateAt: "2023-12-11T11:58:47Z"
    }
  ],
  privatePost: false,
  deleted: false,
  deletedAt: null,
  deletedBy: null,
  moderated: false,
  moderatedAt: null,
  moderatedBy: null,
  moderatedReason: null,
  createdAt: "2023-12-11T11:58:47Z",
  updatedAt: "2023-12-11T12:58:47Z"
}

Get post replies

Method: getPostReplies(postId, filters?)

Method returns all post's replies.

Filters options are same as getPosts method.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

sdk.discussions
  .getPostReplies("postId")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

const filters = {
  limit: 1,
  startAfter: "postId",
  skipDeleted: true,
  sort: "POPULAR",
};

sdk.discussions
  .getPostReplies("postId", filters)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    totalItems: 1,
    nextPageStartsAfter: "postId",
    lastCommentCreateTimestamp: "2023-12-11T11:58:47Z"
  },
  data: [
    {
      id: "postId",
      userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
      userModel: {
        id: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
        name: "Viktor Yordanov",
        avatar: "http://localhost/wp-content/uploads/2023/08/Fyz851FXsAEv824.0-square-3.jpg",
        gender: "male",
        country: {
          id: "profile:cnt:23",
          name: "Bulgaria",
          assets: {
            flag: "https://profile.fansunitedassets.com/country/3a92ffe9-8e19-11eb-b60d-42010a84003b.png",
          },
        },
        birthDate: "1996-11-20",
        followingCount: 3,
        followersCount: 2,
        nickname: null,
      },
      discussionId: "discussionId",
      content: "New awesome post!",
      repliesCount: 0,
      replyId: "postId",
      reactions: [],
      reactionsCount: 0,
      reports: [],
      reportsCount: 0,
      versions: [],
      privatePost: false,
      deleted: false,
      deletedAt: null,
      deletedBy: null,
      moderated: false,
      moderatedAt: null,
      moderatedBy: null,
      moderatedReason: null,
      createdAt: "2023-12-11T11:58:47Z",
      updatedAt: "2023-12-11T12:58:47Z",
    }
  ]
}

Report post

Method: reportPost(postId, reason, reasonDetails?)

Method reports specific post with provided reason and details.

Available options for reason:

  • SPAM
  • NOT_ON_THE_SUBJECT
  • AD
  • COPYRIGHT
  • EXPLICIT_SEXUAL_CONTENT
  • HATEFUL_SPEECH
  • INSULT
  • OTHER

N.B. reasonDetails parameter is optional. However when reason is "OTHER", it is required.

N.B.2 This method is private and it requires JWT.

πŸ“˜

Example call:

sdk.discussions
  .reportPost("postId", "AD")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

sdk.discussions
  .reportPost("postId", "OTHER", "Scam")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    totalItems: 1,
    nextPageStartsAfter: "postId",
    lastCommentCreateTimestamp: "2023-12-11T11:58:47Z"
  },
  data: [
    {
      id: "postId",
      userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
      discussionId: "discussionId",
      content: "New awesome post!",
      repliesCount: 0,
      replyId: "postId",
      reactions: [],
      reactionsCount: 0,
      reports: [
        {
          userId: "userId",
          reason: "AD",
          reasonDetails: null
        },
        {
          userId: "userId",
          reason: "OTHER",
          reasonDetails: "Scam"
        }
      ],
      reportsCount: 2,
      versions: [],
      privatePost: false,
      deleted: false,
      deletedAt: null,
      deletedBy: null,
      moderated: false,
      moderatedAt: null,
      moderatedBy: null,
      moderatedReason: null,
      createdAt: "2023-12-11T11:58:47Z",
      updatedAt: "2023-12-11T12:58:47Z",
    }
  ]
}

Get user's own posts

Method: getOwnPosts(filters?)

Method returns user's own posts.

Filters options are same as getPosts method.

N.B. This method is private and it requires JWT.

πŸ“˜

Example call:

const filters = {
  limit: 1,
  startAfter: "postId",
  skipDeleted: true,
  sort: "POPULAR",
};

sdk.discussions
  .getOwnPosts(filters)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    pagination: {
    	itemsPerPage: 10,
      nextPageStartsAfter: "postId"
    }
  },
  data: [
    {
      id: "postId",
      userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
      discussionId: "discussionId",
      content: "New awesome post!",
      repliesCount: 0,
      replyId: "postId",
      reactions: [],
      reactionsCount: 0,
      reports: [],
      reportsCount: 0,
      versions: [],
      privatePost: false,
      deleted: false,
      deletedAt: null,
      deletedBy: null,
      moderated: false,
      moderatedAt: null,
      moderatedBy: null,
      moderatedReason: null,
      createdAt: "2023-12-11T11:58:47Z",
      updatedAt: "2023-12-11T12:58:47Z",
    }
  ]
}

Get user's posts

Method: getUserPosts(userId, filters?, disableCache?)

Method returns user's posts.

Filters options are same as getPosts method.

The response from API is cached for 30 minutes. With disableCache argument you can avoid cached response.
If no value is provided it will be set to false by default.

N.B. This method is public and it doesn't require JWT.

πŸ“˜

Example call:

const filters = {
  limit: 1,
  startAfter: "postId",
  skipDeleted: true,
  sort: "POPULAR",
};

sdk.discussions
  .getUserPosts("userId", filters)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  meta: {
    pagination: {
      itemsPerPage: 10,
      nextPageStartsAfter: "postId",
    }
  },
  data: [
    {
      id: "postId",
      userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
      discussionId: "discussionId",
      content: "New awesome post!",
      repliesCount: 0,
      replyId: "postId",
      reactions: [],
      reactionsCount: 0,
      reports: [],
      reportsCount: 0,
      versions: [],
      privatePost: false,
      deleted: false,
      deletedAt: null,
      deletedBy: null,
      moderated: false,
      moderatedAt: null,
      moderatedBy: null,
      moderatedReason: null,
      createdAt: "2023-12-11T11:58:47Z",
      updatedAt: "2023-12-11T12:58:47Z",
    }
  ]
}

Posts reactions

React to a post

Method: react(postId, reaction)

Method reacts to the specified post.

The following reactions are allowed:

  • LIKE
  • DISLIKE
  • LOVE
  • LAUGH
  • CARE
  • WOW
  • SAD
  • ANGRY

N.B. This method is private and it requires JWT.

πŸ“˜

Example call:

sdk.discussions
  .reactLike("postId", "LIKE")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Throws error message
  });

Example result

{
  id: "postId",
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  discussionId: "discussionId",
  content: "Content is updated!",
  repliesCount: 0,
  replyId: "postId",
  reactions: [
    {
      id: "LIKE",
      userIds: ["Y44CxUzkpHdypYxcVVlwIQiLNtD2"],
      reactionCount: 1,
    },
  ],
  reactionsCount: 1,
  reports: [],
  reportsCount: 0,
  versions: [
    {
      content: "New awesome post!",
      updateAt: "2023-12-11T11:58:47Z",
    }
  ],
  privatePost: false,
  deleted: false,
  deletedAt: null,
  deletedBy: null,
  moderated: false,
  moderatedAt: null,
  moderatedBy: null,
  moderatedReason: null,
  createdAt: "2023-12-11T11:58:47Z",
  updatedAt: "2023-12-11T12:58:47Z"
}