Project

rails-bot

0.0
No commit activity in last 3 years
No release in over 3 years
It creates a bot for you
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5.1.4
 Project Readme

Rails::Bot

Building a bot for the chatting functionality in the Rails Application. Write now using GoogleCustomSearchApi for the query part. You can check it out here: https://www.ideakart.com (For Desktop Version Only)

Gem Version

Usage

Rails::Bot.conversation(message) => "Hey Just received your message: #{message}"

Rails::Bot.search(message) => #This return the results from the google custom search API

Read this, as a part of this gem uses this for query https://github.com/wiseleyb/google_custom_search_api

Configure:

You need to configure GOOGLE_SEARCH_CX and GOOGLE_API_KEY to config/initializers/google_cse_api.rb:

GOOGLE_API_KEY = "..." GOOGLE_SEARCH_CX = "..."

Installation

Add this line to your application's Gemfile:

gem 'rails-bot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-bot

Then, create the files and initializers code, make sure you have installed "gem 'google_custom_search_api'", "gem 'devise'"

rails g rails:bot:initializer

The above would create files for you

  create  config/initializers/google_initializer.rb => For the google custom seacrh API
  create  config/initalizers/warden_hooks.rb => For Validation at Websocket Connection
  create  app/views/shared/_chat.html.erb => For rendering the view for chat
  create  app/channels/chat_channel.rb => For communicating with the client
  create  app/assets/javascripts/channels/chat.coffee => For communicating with the server
  create  app/jobs/ruby_bot_job.rb => Bot Responds via this Active Job

In your application.html.erb, in body add this

  <%= render "shared/chat"%>

Post that add these methods to your ApplicationHelper(application_helper.rb)

  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

Post that add this to your connection.rb

  identified_by :current_user
 
    def connect
      self.current_user = find_verified_user
    end
     
    private
      def find_verified_user
        if current_user = User.find_by(id: cookies.signed['user.id']) 
          current_user
        else
          reject_unauthorized_connection
        end
      end

Contributing

Contribution directions go here.

License

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