1.1.1-staging • Published 4 years ago

tutosh-apps-chat-lib v1.1.1-staging

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

TutoshChatLib

This library was generated with Angular CLI version 11.2.14.

Installation

To install the Tutosh chat liberary in you angular project, run the following command in your project home directory.

sudo npm i tutosh-apps-chat-lib@latest

It will install latest version of library to your project. You also need to install the socket.io using following command

sudo npm i socket.io-client

Usage

Adding Chat Provider

Add chat Chat library provider to your projects app module as follows. Further you need to add HttpClientModule in imports.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { Chat } from 'tutosh-apps-chat-lib';

@NgModule({
declarations: [
    AppComponent
],
imports: [
    BrowserModule
    HttpClientModule
],
providers: [Chat],
bootstrap: [AppComponent]
})
export class AppModule { }

Import Chat Module

Import the Chat module in your required page and use the features

import { Component } from '@angular/core';
import { Chat } from 'tutosh-apps-chat-lib';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
title = 'testapp';

constructor(public chat:Chat){
    console.log(this.chat.getThreads(2270));
}
}

Features

Initialize the Library

/**
 * Initialize Chat Library
 * @param key API key
 * @returns Validates the API key secret and respond accordinly
 */
init(key: String)

Initialize the SDK

/**
 * Disconnect SDK
 * @returns sucess message as string
 */
closeSDK() : String

Get Threads

/**
 * Fetch list of chat threads
 * @param profileId Profile Id of connected user
 * @returns Array of all the threads available for provided params
*/
getThreads(profileId: Number): string;

Get Support Threads

/**
 * Fetch list of support threads
 * @param profileId Profile Id of connected user
 * @returns Array of all the threads available for provided params
*/
getSupportThreads(profileId: Number): Observable<any>

Get Thread's Chats

/** Fetch 20 specific chat messages of thread @param profileId Profile Id of current user @param sessionId Session Id of thread @param pageNumber Page number for which 20 messages are to be fetched i.e pageNumber 1 will return top 20 messages, pageNumber 2 will return messages from 20 to 40 and so on. @returns It returns 20 messages of provided page number / getThreadChat(profileId: Number, sessionId: String, pageNumber: Number): Observable

Get New Messages

 /**
 * Fetch new messages of specific thread
 * @param sessionId Session Id of thread
 * @param messageId Message Id of last fetched message
 * @returns It returns observable
*/
getNewMessages(sessionId: String, messageId: Number): Observable<any>

Get Previous Messages

/**
 * Get Previous Messages
 * @param sessionId Session ID
 * @param messageId Chat Id
 * @param limit Number of messages to return
 * @returns Observable
 */
getPreviousMessages(sessionId: String, messageId: Number, limit: Number): Observable<any> 

Add New Chat

/**
 * Add chat message to database
 * @param profileId Profile Id of current user
 * @param sessionId Session Id of thread
 * @param message Chat message to be added
 * @param messageTime Date time of message to be added e.g 17:39
 * @param chatType Chat type: Individual | Group | Tutring
 * @param typeId Chat type Id, it can be profileId | groupId or tutoringId associated with chatType
 * @param participants Array of participant Ids (Optional)
*/
addChat(profileId: Number, sessionId: String, message: String, messageTime: String, chatType:String, typeId: Number)

Mark Chats

/**
 * Mark tick of the chat messages
 * @param status Status: 1 for sent, 2 for delivered and 3 for read messages
 * @param profileId Profile Id of current user
 * @param sessionId Session Id of thread
*/
tickChat(status: Number, profileId: Number, sessionId: Number): string;

Send Messages

/**
 * Send the message over Socket system
 * @param profileId Profile Id of sender user
 * @param sessionId Session Id of thread
 * @param message Message to be sent (Optional)
 * @param typing If the user started typing (Optional)
 * @param tick If tick is just marked (Optional)
 * @param options To pass any data objec (Optional)
 */
sendMessage(profileId: Number, sessionId: String, message?: String, typing?: boolean, tick?: boolean): Observable<any>;

Receive Messages

/**
 * Get messages from all users in real time
 * @returns Observeable to listen all incomming messages
 */
getMessages(): Observable<any>;

Uninstall Library

To uninstall tutosh chat library, run the following command in project directory.

npm remove tutosh-apps-chat-lib

Code scaffolding

Run ng generate component component-name --project tutosh-apps-chat-lib to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module --project tutosh-apps-chat-lib.

Note: Don't forget to add --project tutosh-apps-chat-lib or else it will be added to the default project in your angular.json file.

Build

Run ng build tutosh-apps-chat-lib to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with ng build tutosh-apps-chat-lib, go to the dist folder cd dist/tutosh-apps-chat-lib and run npm publish.

Running unit tests

Run ng test tutosh-apps-chat-lib to execute the unit tests via Karma.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.

1.1.1-staging

4 years ago

1.1.1

4 years ago

1.1.1-release

4 years ago