In this project we have implemented apis to manage authentication and live chatting module using Action cable. Below are the APIs list (Module-wise)
- User Registration
- User Login
- Manage Access Token via Refresh Token
- Logout
- Conversations list
- Remove Conversations (Single and bulk)
- Send message (To specific conversation)
- Remove messages in bulk (From loggedin user's list only, receipients will see the messages)
- Delete Messages (From me ony and from all receipients as well)
- Messages List (From a specific Conversation)
- Mark Messages as seen/unseen (Bulk and single)
- Message delivery/seen/unseen tracking (Bulk and single)
We are managing Action Cable notifications by their codes. Here are the codes to handle the received notifications on client applications.
- 10: New Message
- 11: Remove Message
- 12: Seen Message
- 14: Delivered Message
When any activity happen with respect to a message or a new message over the server, client will be notify by these code in Action Cable broadcast on their subscribed channel.
We have documented all of these APIs using postman collections with their responses as well. Please download and import this in your postman to get direct endpoints access to the APIs with required body, headers etc.
Here is the postman collection link https://github.com/TecOrb-Developers/rails-chat-action-cable/blob/main/documentation/Chat-Module.postman_collection.json
Doorkeeper JWT adds JWT token support to the Doorkeeper OAuth library. Complete document for integration is here https://github.com/TecOrb-Developers/rails-doorkeeper-auth
- Node (v 16)
- Yarn (v 1.22.19)
- Ruby (v 3.0.1)
- Rails (v 6.1.4)
- MySQL (v 8.0.29)
- Git (v 2.32.1)
- Redis (v >= 4.2.0)
- Sidekiq (v 6.4.2)
- Action cable (v 6.1.4.1)
- Docker (Optional in case running without containers)
- Prepared with above dependencies
- Created a new Rails app
- Database configuration setup (using MySQL)
- Initialize a local repository using git
- .gitignore file created to add configuration.yml
- configuration.yml file created to initialize environment variables
- Create a new remote repository using GitHub
- Change README.md and documentation added
- Code Commited and Pushed to GitHub repository
* Go to the config directory
* Create a new file with name configuration.yml
Here are the variables we need to define in this file:
DB_DEVELOPMENT: development_db_name
DB_DEVELOPMENT_USERNAME: development_db_username
DB_DEVELOPMENT_PASSWORD: development_db_password
DB_PRODUCTION: production_db_name_xxx
DB_PRODUCTION_USERNAME: production_db_username_xxx
DB_PRODUCTION_PASSWORD: production_db_password_xxx
DB_TEST: test_db_name
JWT_SECRET: jwt_secret_strong_xxxxxxxxxxxxxxxxxxxxxxx
MYSQL_SOCKET: /tmp/mysql.sock
ACTIONCABLE_BASE: https://your-frontend-application-endpoint
We are using Doorkeeper gem with JWT authentication to manage signup and login module.
# For making this application serve as an OAuth-Provider
# which can be used by OAuth Clients like a custom Webapp
gem 'doorkeeper'
## We are using JWT as the token generator for Doorkeeper hence this gem
gem 'doorkeeper-jwt'
We need to configure Doorkeeper as we already did in another sample
We have improved above module for the registration process and session management in this repo. You can go thorugh with the commits to get more details.
You can check detailed documentation on configurations from below links:
Here are some of the major gems we have used in this project also we must go through for future uses.
- gem 'mysql2', '~> 0.5' # For databse. Here is the link
- gem 'doorkeeper-jwt' # For authentication. Here is the link
- gem 'bcrypt', '~> 3.1.7' # For authentication. Here is the link
- gem 'will_paginate', '~> 3.1.0' # For paginate active records. Here is the link
- gem 'active_model_serializers' # For preparing object-oriented JSON responses. Here is the link
- gem 'draper' # For using model decorators. Here is the link
- gem 'redis', '~> 4.0' # For caching database. Here is the link
- gem 'sidekiq', '~> 6.4.0' # For background processing (job scheduler). Here is the link
For better use of gem 'factory_bot_rails'
here is the detailed documentation about installation, configurations and uses.
User need to subscribe a chat channel to get notify through action cable. Action Cable url will be send by server where the application is hosted followed by the /cable path. Channel name is initiated by a prefix 'notify_' and user's id. To subscribe a channel user need to send their access token in 'session_token' key at the time of subscription request. Once user will be authenticated successfully, server will allow to subscribe the requested channel for the client.