@ux-xu/emo-platform-api-nodejs
v1.0.2
Published
bocco emo Platform API client library for node.js
Downloads
2
Readme
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.