0.12.0 • Published 5 months ago

@wezard/halo-core v0.12.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Halo Core

javascript NPM version

Table of Content

  1. Installation
    1. Firebase
  2. Usage
    1. Initialization
    2. Authentication and user creation
  3. Overview
    1. User
    2. Agent
    3. Room
  4. Create an Halo Module

Installation

Firebase

Add Halo dependencies:

yarn add @wezard/halo-core @wezard/react-native-halo-firebase

Add Firebase dependencies:

yarn add @react-native-firebase/app @react-native-firebase/auth @react-native-firebase/firestore @react-native-firebase/storage

Setup Firebase following official guide.

Usage

Initialization

import { halo } from '@wezard/halo-core'

// ...

const initChat = () => {
    halo.initialize('firebase')
}

Authentication and user creation

Halo Firebase needs to authenticate the user before they perform any action.

import { halo } from '@wezard/halo-core'
import auth from '@react-native-firebase/app'

// ...
const signUp = async () => {
    try {
        await auth().createUserWithEmailAndPassword(email, password)
        const user = await halo.createUser({
            firstName: 'Matteo',
            lastName: 'Bianchi',
            nickname: 'mattyb98',
            image: 'https://avatar.com'
        })
        // save user data
    } catch (error) {
        // handle error
    }
}

const signIn = async () => {
    try {
        const userCredentials = await auth().signInWithEmailAndPassword(email, password)
        const user = await halo.getUser(userCredentials.user.uid)
        // save user data
    } catch (error) {
        // handle error
    }
}

Overview

User

methodreturndescription
getUserUserDetailsget user info by user id
createUserUserDetailscreate chat user reference
updateUserUserDetailsupdate chat user
updateUserDeviceTokenvoidupdate device token in order to receive notifications
fetchUsersvoidregister a callback triggered when a user is added o updated

Agent

methodreturndescription
getAgentAgentDetailsget agent info by agent id
createUserAgentDetailscreate chat agent reference
updateAgentAgentDetailsupdate chat agent
updateAgentDeviceTokenvoidupdate device token in order to receive notifications

Room

methodreturndescription
getRoomsRoomDetails[]get rooms details collection with pagination
getRoomDetailsRoomDetailsget room details
createRoomWithUsersRoomDetailscreate private or group room object
createRoomForAgentsRoomDetailscreate an agent room based on a specific tag
joinUserRoomDetailsadd a user to a group room
joinAgentRoomDetailsadd an agent to an agent room, an agent must be added to the room in order to have write permissions
removeUserRoomDetailsremove a user from a group room
sendTextMessageMessageType.Anysend a message
sendFileMessageMessageType.Anysend a message with an attachement, it handles file upload
sendFileMessageFromUrlMessageType.Anysend a message with an attachement, it uses file url passed as argument to store file
readMessagevoidmark message read for one user
deleteMessagevoiddelete message for all room users
getRoomMediaMessageType.MediaInfo[]get room media filtered by content type
fetchRoomsvoidregister a callback triggered when a room is added or updated
fetchRoomsByAgentvoidregister a callback triggered when a room with one or more tags is added or updated
fetchMessagesvoidregister a callback triggered when messages are added to a room

Create an Halo Module

In order to create an Halo Module, init a React Native library, you can use create-react-native-library.

Then add Halo dependency:

yarn add @wezard/halo-core

Now you have to implements IUser, IAgent and IRoom interfaces:

  • user.ts
import { IUser } from '@wezard/halo-core'

export class User implements IUser {
    // implements IUser methods
}
  • agent.ts
import { IAgent } from '@wezard/halo-core'

export class Agent implements IAgent {
    // implements IAgent methods
}
  • room.ts
import { IRoom } from '@wezard/halo-core'

export class Room implements IRoom {
    // implements IRoom methods
}

And create an index.ts file that exports classes

export * from './agent'
export * from './room'
export * from './user'
0.11.0

5 months ago

0.12.0

5 months ago

0.10.0

5 months ago

0.9.0

5 months ago

0.8.1

5 months ago

0.8.0

5 months ago

0.8.2

5 months ago

0.7.0

5 months ago

0.6.0

5 months ago

0.5.1

10 months ago

0.5.0

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago