Skip to content

Instantly share code, notes, and snippets.

@sendbird-community
Created March 17, 2023 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sendbird-community/9967c26934269204660e1b3009f0c70d to your computer and use it in GitHub Desktop.
Save sendbird-community/9967c26934269204660e1b3009f0c70d to your computer and use it in GitHub Desktop.
Helper methods
class HTTPError extends Error {
constructor({status, response}) {
super(`HTTP request failed: ${status} ${statusText}`);
this.response = response;
}
}
const makePostCall = async (url, body) => {
const result = await $request.post(url, {headers, body})
return JSON.parse(result.response)
}
const fetchNewSendBirdSessionToken = async (userId) => {
const url = `https://api-${APP_ID}.sendbird.com/v3/users/${userId}/token`
const body = JSON.stringify({expires_at: Date.now() + 1000 * 60 * 60});
return makePostCall(url, body)
}
const createNewSendbirdUser = async (userId) => {
const url = `https://api-${APP_ID}.sendbird.com/v3/users`
const body = JSON.stringify({user_id: userId, nickname: "", profile_url: ""});
return makePostCall(url, body)
}
const createNewSendbirdGroupCallRoom = async (type = 'small_room_for_video') => {
const url = `https://api-${APP_ID}.calls.sendbird.com/v1/rooms`
const body = JSON.stringify({type});
return makePostCall(url, body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment