0.0.2 • Published 6 years ago

firebase-messanger-api v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

##Firebase messanger API

API for creating messangers/chats etc with realtime communication and saving history to firebase realtime database. Main features:

  • create chats
  • invite user to the chat
  • ability to decline invites
  • chats list
  • unread messages

##API

Firebase based messanger API, will store data to firebase realtime database in case firebase was initialized.

initChat (callback)

Initialize chat when firebase user was authorized

callback(optional) - function that will be called after chat initialization. Params are:

  • displayName - firebase user name,
  • uid - firebase user id
initChat(({ displayName, uid }) => {
  Log(`${displayName} user was logged in`);
});

createChat ({ name, userId, callback })

Create a new chat with one user and set this user as admin for it. Parameters:

  • name - name for the chat. Default - 'Chat'
  • userId - uid of firebase user. Default - current authorized firebase user id
  • callback - callback function, will be called with error if exist and chat id
    • id - chat id
    • name - chat name
    • moderator - admin user id
createChat({
  name: 'Awesome chat#42',
  callback: (err, id) => {
    if (!err) Log(`Chat with ${id} was created`)
  }
})

###setChat (chatId, callback) Set current chat for the user

  • chatId - firebase chat id
  • callback - will be called after chat was/wasn't assigned
    • id - chat id in the database
    • moderator - administrator of the chat
    • name - title of the chat
    • users - list of users assigned to the chat

###addUserToChat ({ userId, chatId, chatName }) Add user to the chat without sending invitation

  • userId - firebase user id that added target user to the chat
  • chatId - chat id for adding
  • chatName - name of the chat

###inviteUserToChat ({ userId, id, name, from }) Send chat invitation to user

  • userId - user that will receive the invite
  • id - chat id
  • name - chat name
  • from - user that sent the invite. Default - current user

###getChatList ({ userId, callback }) Return list of chats and unread messages

  • userId - firebase user id for retrieving the chats
  • callback - will be called when lists of chats and unread messages were received. Argument is an array, empty or with objects:
    • id - chat id
    • name - chat name
    • unreadMessages - unread chat messages

###getChatMessages (chatId, callback) Return chat messages. By default will return current chat messages

  • chatId - chat id for retrieving the messages. Default - current chat
  • callback - will be called when list of messages was received
    • message - message string
    • name - name of user that have sent the message
    • time - time when message was sent
    • userId - firebase id of message author

###setMessageRead (messageId, userId, chatId) Mark message as read

  • messageId - message id that should be marked as read
  • userId - id of user that read the message
  • chatId - id of chat that has the message

###sendMessage (message, chatId) Send message from current user to a chat

  • message - message to send
  • chatId - chat to send message. Default - current chat

##TODO:

  • add firebase mock for the tests
  • add examples web/mobile
  • add build config
  • add DB examples
  • rewrite all to promises

##Licensee MIT

0.0.2

6 years ago

0.0.1

6 years ago