cometchat-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

cometchat-api

npm package


cometchat-api

simple cometchat api methods with typescript support

🚧 WIP – welcome pr

Install

# npm
npm install cometchat-api

# yarn
yarn add cometchat-api

# pnpm
pnpm add cometchat-api

Usage

import { useCometchatApi } from 'cometchat-api'

// set you env
const chat = useCometchatApi({
  apiKey: process.env.COMETCHAT_API_KEY,
  appId: process.env.COMETCHAT_APP_ID,
  region: process.env.COMETCHAT_REGION
})

// use in code
const user = await chat.getUser('superhero1')

//  {
//    "data": {
//      "uid": "superhero1",
//      "name": "Iron Man"
//      ...
//    }
//  }

if (user) {
  console.log(user.data.name) // Iron Man
} else {
  console.log(user) // null
}

Log Errors

import { isCometchatApiError } from 'cometchat-api'
import { AxiosError } from 'axios'

const errorHandler = (error: AxiosError) => {
  if (error.response && isCometchatApiError(error.response.data)) {
    console.error(error)
  }

  return Promise.reject(error)
}

// https://github.com/axios/axios#interceptors
chat.instance.interceptors.response.use(
  (response) => response,
  (error) => errorHandler(error)
)

Package Sidebar

Install

npm i cometchat-api

Weekly Downloads

5

Version

1.0.7

License

MIT

Unpacked Size

8.46 kB

Total Files

5

Last publish

Collaborators

  • reslear