Constructor
new SidechatAPIClient(tokenopt, rootUrl)
Create a new instance of the API client
| Name | Type | Attributes | Description |
|---|---|---|---|
token | types. | <optional> | user bearer token |
rootUrl | String | custom API root URL for mocking or using other server |
- Since
- 2.0.0-alpha.0
Members
apiRoot :String
Root URL for every API request
- String
- Default Value
- "https://api.sidechat.lol"
(constant) defaultHeaders :Object
Default headers for every API request
- Object
userToken :types.SidechatAuthToken
User bearer token
- types.
SidechatAuthToken
Methods
checkEmailVerification()
Check is the user's email is verified.
- Since
- 1.0.0
checkUsername(username) → {Promise.<Boolean>}
Checks if user can set their username to a string
| Name | Type | Description |
|---|---|---|
username | String | string to check |
- Since
- 2.3.6
whether or not username is valid and unused
- Type:
- Promise.<Boolean>
createComment(parentPostID, text, groupID, replyCommentIDopt, topLevelReplyIDopt, assetListopt, disableDMsopt, anonymousopt) → {Promise.<types.SidechatPostOrComment>}
Creates a comment on a post
| Name | Type | Attributes | Description |
|---|---|---|---|
parentPostID | String | alphanumeric ID of post on which this comment is made | |
text | String | text content of comment | |
groupID | String | alphanumeric ID of group in which the parent post resides | |
replyCommentID | String | <optional> | alphanumeric ID of comment to reply to. Falls back to parentPostID |
topLevelReplyID | String | <optional> | alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID |
assetList | Array.<types.SidechatSimpleAsset> | <optional> | list of assets to attach |
disableDMs | Boolean | <optional> | prevent direct messages being sent to comment's author |
anonymous | Boolean | <optional> | whether or not to hide user's name and icon on comment |
- Since
- 2.2.0
created comment
- Type:
- Promise.<types.SidechatPostOrComment>
createPost(text, groupID, assetListopt, disableDMsopt, disableCommentsopt, anonymousopt, pollOptionsopt) → {Promise.<types.SidechatPostOrComment>}
Creates a new post in the specified group
| Name | Type | Attributes | Description |
|---|---|---|---|
text | String | text content of comment | |
groupID | String | alphanumeric ID of group in which the parent post resides | |
assetList | Array.<types.SidechatSimpleAsset> | <optional> | list of assets to attach. |
disableDMs | Boolean | <optional> | prevent direct messages from being sent to post's author |
disableComments | Boolean | <optional> | whether or not comments should be disabled on post |
anonymous | Boolean | <optional> | whether or not to hide user's name and icon on post |
pollOptions | Array.<String> | <optional> | List of poll options. If provided, a poll will be created with these options. |
- Since
- 2.2.0
the created post
- Type:
- Promise.<types.SidechatPostOrComment>
deletePostOrComment(postOrCommentID)
Deletes a post or comment that the user created
| Name | Type | Description |
|---|---|---|
postOrCommentID | String | alphanumeric ID of post to delete |
- Since
- 2.2.0
getAssetLibrary() → {Promise.<Array.<types.SidechatLibraryAsset>>}
Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
- Since
- 2.0.6
- Type:
- Promise.<Array.<types.SidechatLibraryAsset>>
getAvailableGroups(onePage) → {Promise.<Array.<types.SidechatGroup>>}
Gets groups to be displayed on the "Explore Groups" page
| Name | Type | Description |
|---|---|---|
onePage | Boolean | whether or not results should be returned as a single page |
- Since
- 2.0.0-alpha.0
- Type:
- Promise.<Array.<types.SidechatGroup>>
getCurrentUser() → {Promise.<types.SidechatCurrentUser>}
Gets the current authenticated user and a list of the groups of which they are members.
- Since
- 2.1.0
- Type:
- Promise.<types.SidechatCurrentUser>
getDMThread(id) → {Promise.<types.SidechatDirectThread>}
Gets a single direct message thread
| Name | Type | Description |
|---|---|---|
id | String | alphanumeric ID of the chat to fetch |
- Since
- 2.4.4
- Type:
- Promise.<types.SidechatDirectThread>
getDMs() → {Promise.<Array.<types.SidechatDirectThread>>}
Gets a list of the user's direct messages
- Since
- 2.4.4
- Type:
- Promise.<Array.<types.SidechatDirectThread>>
getGroupChats()
Retrieves joinable group chats
- Since
- 2.3.5
getGroupMetadata(groupIDopt) → {Promise.<types.SidechatGroup>}
Gets the metadata of a group from its ID
| Name | Type | Attributes | Description |
|---|---|---|---|
groupID | String | <optional> | alphanumeric ID of a group to get. Falls back to user's primary group. |
- Since
- 2.1.0
- Type:
- Promise.<types.SidechatGroup>
getGroupPosts(groupID, category, cursoropt) → {Promise.<types.SidechatPostsAndCursor>}
Fetches posts from the specified category in a group
| Name | Type | Attributes | Description |
|---|---|---|---|
groupID | String | group ID | |
category | "hot" | | category to filter posts | |
cursor | types. | <optional> | cursor string |
- Since
- 1.0.0
List of posts and cursor
- Type:
- Promise.<types.SidechatPostsAndCursor>
getPost(postID, includeDeleted) → {Promise.<types.SidechatPostOrComment>}
Fetches a single post with just its ID
| Name | Type | Description |
|---|---|---|
postID | String | ID of post to fetch |
includeDeleted | Boolean | undocumented |
- Since
- 2.3.0
post object
- Type:
- Promise.<types.SidechatPostOrComment>
getPostComments(postID) → {Promise.<Array.<types.SidechatPostOrComment>>}
Get all the commments on a post
| Name | Type | Description |
|---|---|---|
postID | String | post ID to get comments for |
- Since
- 2.0.0-alpha.0
list of comments
- Type:
- Promise.<Array.<types.SidechatPostOrComment>>
getUpdates(groupIDopt)
Get updated status for user and group
| Name | Type | Attributes | Description |
|---|---|---|---|
groupID | String | <optional> | ID of a specific group to retrieve info from. Falls back to user's primary group. |
- Since
- 2.1.0
getUserAndGroup(groupIDopt)
Get updated status for user and group
| Name | Type | Attributes | Description |
|---|---|---|---|
groupID | String | <optional> | ID of a specific group to retrieve info from. Falls back to user's primary group. |
- Since
- 1.0.0
- Deprecated
- since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
getUserContent(contentType) → {Promise.<Array.<types.SidechatPostOrComment>>}
Fetches the posts or comments that the user has created
| Name | Type | Description |
|---|---|---|
contentType | "posts" | | type of user content to fetch |
- Since
- 2.3.5
post object
- Type:
- Promise.<Array.<types.SidechatPostOrComment>>
getUserPosts(username) → {Promise.<Array.<types.SidechatPostOrComment>>}
Fetches a public user's posts
| Name | Type | Description |
|---|---|---|
username | String | username of the user to fetch |
- Since
- 2.6.0
- Type:
- Promise.<Array.<types.SidechatPostOrComment>>
getUserProfile(username) → {Promise.<types.SidechatProfile>}
Fetches a public user profile
| Name | Type | Description |
|---|---|---|
username | String | username of the user to fetch |
- Since
- 2.6.0
- Type:
- Promise.<types.SidechatProfile>
hidePostsFromUser(postID)
Hides posts from user
| Name | Type | Description |
|---|---|---|
postID | String | alphanumeric ID of post to hide |
- Since
- 2.6.2
joinGroupChat(groupChatID, displayName, emoji, primaryColor, secondaryColor)
Joins a group chat. To mimic the official client, use the user's display name and icon by default.
| Name | Type | Description |
|---|---|---|
groupChatID | String | alphanumeric ID of group chat to join |
displayName | String | display name to use in chat |
emoji | String | emoji to use as icon |
primaryColor | String | hex string of primary color |
secondaryColor | String | hex string of secondary color |
- Since
- 2.3.5
loginViaSMS(phoneNumber)
Initiate the login process with a phone number. Should be followed up with verifySMSCode().
| Name | Type | Description |
|---|---|---|
phoneNumber | Number | US phone number (WITHOUT +1) to send verification code to |
- Since
- 1.0.0
readActivity(activityID)
Marks an activity item as read
| Name | Type | Description |
|---|---|---|
activityID | String | alphanumeric ID of activity object |
- Since
- 2.3.2
registerEmail(email)
Initiate the email setup process. Should be followed up with checkEmailVerification().
| Name | Type | Description |
|---|---|---|
email | String | school email address to send verification code to |
- Since
- 1.0.0
- Tutorials
searchAvailableGroups(query) → {Promise.<Array.<types.SidechatGroup>>}
Searches for new groups based on a query keyword
| Name | Type | Description |
|---|---|---|
query | String | the string to search for. This will be encoded, so strings with spaces and special characters are okay. |
- Since
- 2.6.0
- Type:
- Promise.<Array.<types.SidechatGroup>>
sendDM(chatID, text, clientID, assets, anonymous)
Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
| Name | Type | Description |
|---|---|---|
chatID | String | alphanumeric ID of the chat to send to |
text | String | text content of message |
clientID | String | alphanumeric device ID |
assets | Array.<types.SidechatAsset> | array of assets to send |
anonymous | Boolean | whether the DM should be sent anonymously |
- Since
- 2.4.4
sendRequest(endpoint, methodopt, bodyopt, headersopt, stripHeadersopt)
Run an arbitrary API request using the current client's authentication
| Name | Type | Attributes | Description |
|---|---|---|---|
endpoint | String | API endpoint to request (e.g. "/v1/posts") | |
method | "GET" | | <optional> | HTTP method to use |
body | Object | <optional> | body to send with the request |
headers | Object | <optional> | custom headers to send with the request |
stripHeaders | Boolean | <optional> | remove the default headers from the request |
- Since
- 2.4.9
setAPIRoot(url)
Manually set the root URL for all API requests. This can be used for mocking requests or redirecting them to a different server
| Name | Type | Description |
|---|---|---|
url | String | new root URL to set |
- Since
- 2.3.9
setAge(age, registrationID)
Set the user's age. If this function succeeds, the user will be authenticated for future requests.
| Name | Type | Description |
|---|---|---|
age | Number | user's age in years |
registrationID | String | the registration ID generated by verifySMSCode() |
- Since
- 1.0.0
setDeviceID(deviceId)
Set the device ID of the current user
| Name | Type | Description |
|---|---|---|
deviceId | String | the device ID to set |
- Since
- 1.0.0
setGroupMembership(groupID, isMember)
Joins or leaves a group
| Name | Type | Description |
|---|---|---|
groupID | String | alphanumeric ID of group to join or leave |
isMember | Boolean | whether or not the user should be a member of the group |
- Since
- 2.3.8
setToken(token)
Manually set the currently signed in user's token. Generally try to avoid this and instead either pass a token to the constructor or login automatically through the auth functions
| Name | Type | Description |
|---|---|---|
token | types. | user bearer token |
setUserBio(userID, bio)
Sets the bio text of a user
| Name | Type | Description |
|---|---|---|
userID | String | alphanumeric ID of user |
bio | String | text to set as bio |
- Since
- 2.5.6
setUserIcon(userID, emoji, primaryColor, secondaryColor)
Sets the conversation icon of a user
| Name | Type | Description |
|---|---|---|
userID | String | alphanumeric ID of user |
emoji | String | emoji to set as icon |
primaryColor | String | hex string (including #) of primary color |
secondaryColor | String | hex string (including #) of secondary color |
- Since
- 2.2.1
setUsername(userID, username)
Changes the username of the current user
| Name | Type | Description |
|---|---|---|
userID | String | alphanumeric ID of user |
username | String | new username to set |
- Since
- 2.3.6
setVote(postID, action)
Upvote or downvote, or unvote a post
| Name | Type | Description |
|---|---|---|
postID | String | post ID to vote on |
action | types. | whether to upvote, downvote, or reset vote |
- Since
- 2.0.0-alpha.0
startDM(text, clientID, postID, anonymous, postContext)
Creates a new direct message thread
| Name | Type | Description |
|---|---|---|
text | String | text content of message |
clientID | String | alphanumeric ID of devide |
postID | String | alphanumeric ID of post or comment |
anonymous | Boolean | whether the DM should be sent anonymously |
postContext | "feed" | context of post (mostly undocumented, defaults to "feed") |
- Since
- 2.4.4
unhidePostsFromAllUsers()
Unhides all posts from all users
- Since
- 2.6.2
uploadAsset(uri, mimeType, nameopt) → {Promise.<String>}
Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
| Name | Type | Attributes | Description |
|---|---|---|---|
uri | String | URI of the asset to upload | |
mimeType | String | mimetype of the asset (e.g. "image/png") | |
name | String | <optional> | filename of the asset |
- Since
- 2.5.1
URL of the uploaded asset
- Type:
- Promise.<String>
verifySMSCode(phoneNumber, code)
Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
| Name | Type | Description |
|---|---|---|
phoneNumber | Number | US phone number (WITHOUT +1) that verification code was sent to |
code | String | the verification code |
- Since
- 1.0.0
viewPollResults(pollId)
Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
| Name | Type | Description |
|---|---|---|
pollId | String | alphanumeric ID of poll to vote on |
- Since
- 2.5.4
voteOnPoll(pollId, choiceIndex)
Votes on a poll attached to a post
| Name | Type | Description |
|---|---|---|
pollId | String | alphanumeric ID of poll to vote on |
choiceIndex | Number | index of the choice to vote on |
- Since
- 2.5.4