@ux-xu/emo-platform-api-nodejs
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

BOCCO emo platform api client for node.js

Installation

npm i emo-platform-api-nodejs

Usage

Set ACCESS_TOKEN environment variable. You can get your access token at the dashboard

import type { AxiosError } from 'axios'
import { EmoApiClient } from '@ux-xu/emo-platform-api-nodejs'

const apiClient = new EmoApiClient({
  accessToken: 'YOUR ACCESS TOKEN',
  refreshToken: 'YOUR REFRESH TOKEN',
})

// Get my account information
apiClient.getMe()
  .then(response => {
    console.log(response)
  })
  .catch((error: AxiosError) => {
    console.error(`Status code: ${error?.response?.status}`)
    console.error(error?.response?.data)
    console.log(error)
  })

// Get my rooms
apiClient.getRooms()
  .then(response => {
    console.log(response)
  })
  .catch((error: AxiosError) => {
    console.error(`Status code: ${error?.response?.status}`)
    console.error(error?.response?.data)
  })

// response example
{
  listing: { offset: 0, limit: 50, total: 1 },
  rooms: [
    {
      uuid: 'bcbcbcbc-1234-5678-abcd-aaaaaaaaaaaa',
      name: 'My first room',
      roomType: 'normal',
      roomMembers: [Array]
    }
  ]
}

// Post a message
// You can obtain uuids of rooms from `getRooms` API.
const roomUuid = 'bcbcbcbc-1234-5678-abcd-aaaaaaaaaaaa'
apiClient
  .postTextMessage(roomUuid, {
    text: 'Hello, BOCCO!',
  })
  .then(response => {
    console.log(response)
  })
  .catch((error: AxiosError) => {
    console.error(`Status code: ${error?.response?.status}`)
    console.error(error?.response?.data)
  })

Then you will see the response of GET /v1/me

Please see further documentation at docs/index.html

Library development

Setup

  • Node.js 16+ required.
yarn install

Build

yarn build

Output will be placed under /dist.

Build & watch

yarn build:watch

Update documentation

yarn doc

Documentation will be placed under docs/.

Running development script

To call SDK functions, modifying dev.ts would be easy.

yarn dev:watch

Whenever you save dev.ts, it's recompiled and run.

Dependencies (4)

Dev Dependencies (20)

Package Sidebar

Install

npm i @ux-xu/emo-platform-api-nodejs

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

42.5 kB

Total Files

12

Last publish

Collaborators

  • yusakuxxu
  • siwai