Giter VIP home page Giter VIP logo

activeadmin-chat's Introduction

ActiveAdmin::Chat

Build Status Maintainability Test Coverage

Get a chat for your ActiveAdmin app out of the box.

Prerequisites

  • It assumes you have models for your admins and users in place.
  • It assumes that your users have an email attribute.
  • For production you need to configure ActionCable by providing it with a Redis or Postgres connection in config/cable.yml.

Installation

Add to Gemfile:

gem 'activeadmin-chat'

And then run:

$ bundle install

This gem requires Webpacker for the Javascript. Add the npm package:

$ yarn add @rootstrap/activeadmin-chat

And install it:

$ yarn install

Install ActiveAdmin::Chat:

$ rails generate active_admin:chat:install

It will generate:

  • Conversation and Message models and migrations.
  • Initializer that configures the model names for conversation, message, admin user and user.
  • Default chat page.

You can customize the namings of the models when installing ActiveAdmin::Chat with the usage of the --conversation_model_name, --message_model_name, --admin_user_model_name and --user_model_name flags.

For example:

$ rails generate active_admin:chat:install --conversation_model_name=chat

Once you've successfully installed ActiveAdmin::Chat, run:

$ rails db:migrate

Add including of CSS to app/assets/stylesheets/active_admin.css.scss:

@import 'active_admin/chat';

Create a file named app/javascript/packs/activeadmin-chat.js, with the following content:

import '@rootstrap/activeadmin-chat';

Example diagram

Usage

All you need to get the chat up and running is to authenticate your users in the websocket connection in app/channels/application_cable/connection.rb. It's important that you identify them as the current_user here, this will be used by the gem internally.

For example with the devise gem:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    private

    def find_verified_user
      verified_user = env['warden'].user

      reject_unauthorized_connection unless verified_user

      verified_user
    end
  end
end

Customization

You can change the chat page name and namespace the same way you do with other ActiveAdmin pages.

If you'd like to change the chat styling you can override the following classes:

  • .active-admin-chat__title: Title above the conversations list
  • .active-admin-chat__conversations-list-container, .active-admin-chat__conversations-list and .active-admin-chat__conversation-item: List of conversations
  • .active-admin-chat__conversation-history-container and .active-admin-chat__conversation-history: Conversation panel
  • .active-admin-chat__message-container: Message in the conversation panel
  • .active-admin-chat__send-message-container: Send message button

If you'd like to change the whole HTML you can do it in the chat page by specifying its content:

ActiveAdmin.register_chat 'Chat' do
  content do
    # your code
  end
end

If you'd like to change the controller actions you can do it in the chat page by specifying its controller:

ActiveAdmin.register_chat 'Chat' do
  controller do
    def show
      # your code
    end
  end
end

If you'd like to add a button in the user's index in the admin dashboard to start a chat with a user:

ActiveAdmin.register_chat User do
  index do
    # your code
    actions do |user|
      send_message_link user
    end
  end
end

Contributing

Bug reports (please use Issues) and pull requests are welcome on GitHub at https://github.com/rootstrap/activeadmin-chat. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Credits

Active Admin Chat is maintained by Rootstrap with the help of our contributors.

activeadmin-chat's People

Contributors

dependabot[bot] avatar federicoaldunate avatar santiagovidal avatar santib avatar vitogit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activeadmin-chat's Issues

Encrypt messages

To prevent security issues, encrypt the messages before saving them in the DB

Missing GitHub project

As per Open Source improvements, GitHub project should be used to professionalize maintenance.

Create a demo app

Create a demo app and host it on Heroku so it's easy to try the gem

Reestructure JS

Instead of providing the JS as part of the asset pipeline, move all the JS into a javascript folder in the root path which will be packed and served through npm

Add StimulusReflex

Install latest version of StimulusReflex and make sure to upgrade dependencies (e.g. Rails 6+)

Use CableReady for admin chat

  • Install CableReady
  • Change as much Javascript code to Ruby (using CableReady) for the admin chat
  • This will require to set up a different ActionCable Channel that's only for the admin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.