rails-bot 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -2
- data/lib/rails/bot/initializer_generator.rb +17 -0
- data/lib/rails/bot/railtie.rb +4 -0
- data/lib/rails/bot/version.rb +1 -1
- data/lib/rails/bot.rb +2 -0
- data/lib/templates/chat.coffee +36 -0
- data/lib/templates/chat.html.erb +253 -0
- data/lib/templates/chat_channel.rb +16 -0
- data/lib/templates/google_initializer.rb +2 -0
- data/lib/templates/ruby_bot_job.rb +10 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0139159d43fec6245f10835e803d79b5cfd1b3eb'
|
4
|
+
data.tar.gz: b36b8d5edd3c0883c201c41b216faa9a164e8cab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6159c67c785866d10f729aff1b421107f66412f3d2ee4455bea34ce1ff6742574c9921012fb39ff4583f14aa824ea5b58d144442e1cd1b0c7b88a244ba279b
|
7
|
+
data.tar.gz: a9708ccdaa4cd1151c072083321c9065738f12afee2c288ff17faf146834326de74c2d53cd5062b3a35dca72d451f5bb727d347d826d0c8d78b3ee5de48b4958
|
data/README.md
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# Rails::Bot
|
2
|
-
|
2
|
+
Building a bot for the chatting functionality in the Rails Application. Write now using GoogleCustomSearchApi for the query part.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
|
6
|
+
Rails::Bot.conversation(message)
|
7
|
+
=> "Hey Just received your message: #{message}"
|
8
|
+
|
9
|
+
Rails::Bot.search(message)
|
10
|
+
=> #This return the results from the google custom search API
|
11
|
+
|
12
|
+
Read this, as a part of this gem uses this for query
|
13
|
+
https://github.com/wiseleyb/google_custom_search_api
|
14
|
+
|
15
|
+
## Configure:
|
16
|
+
You need to configure GOOGLE_SEARCH_CX and GOOGLE_API_KEY to config/initializers/google_cse_api.rb:
|
17
|
+
|
18
|
+
GOOGLE_API_KEY = "..."
|
19
|
+
GOOGLE_SEARCH_CX = "..."
|
20
|
+
|
6
21
|
|
7
22
|
## Installation
|
8
23
|
Add this line to your application's Gemfile:
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Rails::Bot::InitializerGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path("../../../templates", __FILE__)
|
3
|
+
def create_initializer_file
|
4
|
+
#create_file "config/initializers/google_initializer.rb", "# Add initialization content here"
|
5
|
+
copy_file "google_initializer.rb", "config/initializers/google_initializer.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_chat_file
|
9
|
+
copy_file "chat.html.erb", "app/views/shared/_chat.html.erb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_channel_code
|
13
|
+
copy_file "chat_channel.rb", "app/channels/chat_channel.rb"
|
14
|
+
copy_file "chat.coffee", "app/assets/javascripts/channels/chat.coffee"
|
15
|
+
copy_file "ruby_bot_job.rb", "app/jobs/ruby_bot_job.rb"
|
16
|
+
end
|
17
|
+
end
|
data/lib/rails/bot/railtie.rb
CHANGED
data/lib/rails/bot/version.rb
CHANGED
data/lib/rails/bot.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
App.chatChannel = App.cable.subscriptions.create { channel: "ChatChannel", room: "Bot_Room" },
|
2
|
+
received: (data) ->
|
3
|
+
@appendLine(data)
|
4
|
+
|
5
|
+
appendLine: (data) ->
|
6
|
+
html = @createLine(data)
|
7
|
+
$("#room").append(html)
|
8
|
+
$('#chat-message-counter').text(parseInt($('#chat-message-counter').text()) + 1)
|
9
|
+
$('.chat-feedback').hide()
|
10
|
+
$('#room').animate({scrollTop: $('#room').prop("scrollHeight")}, 500);
|
11
|
+
|
12
|
+
|
13
|
+
createLine: (data) ->
|
14
|
+
"""
|
15
|
+
<div class="chat-message clearfix">
|
16
|
+
<img src="http://gravatar.com/avatar/2c0ad52fc5943b78d6abe069cc08f320?s=32" alt="" width="32" height="32">
|
17
|
+
<div class="chat-message-content clearfix">
|
18
|
+
<span class="chat-time">#{data["time"]}</span>
|
19
|
+
<h5>#{data["sent_by"]}</h5>
|
20
|
+
<p>#{data["body"]}</p>
|
21
|
+
</div> <!-- end chat-message-content -->
|
22
|
+
</div> <!-- end chat-message -->
|
23
|
+
<hr>
|
24
|
+
"""
|
25
|
+
$(document).ready ->
|
26
|
+
$('form#message_form').submit (event) -> #HERE
|
27
|
+
App.chatChannel.send({ sent_by: $('#name').val(), body: $('#msg_text').val() })
|
28
|
+
event.preventDefault()
|
29
|
+
$('#chat-message-counter').text('0')
|
30
|
+
$('.chat-feedback').show()
|
31
|
+
$('#msg_text').val('')
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,253 @@
|
|
1
|
+
<div id="live-chat">
|
2
|
+
|
3
|
+
<header class="clearfix">
|
4
|
+
<a href="#" class="chat-close">x</a>
|
5
|
+
<h4>Chat</h4>
|
6
|
+
<span class="chat-message-counter" id="chat-message-counter">0</span>
|
7
|
+
</header>
|
8
|
+
<% if current_user%>
|
9
|
+
<div class="chat">
|
10
|
+
<div class="chat-history" id="room">
|
11
|
+
|
12
|
+
</div> <!-- end chat-history -->
|
13
|
+
|
14
|
+
<p class="chat-feedback">Your partner is typing…</p>
|
15
|
+
<form action="#" method="post" id="message_form" data-remote="true">
|
16
|
+
<fieldset>
|
17
|
+
<input type="text" placeholder="Type your message…" id="msg_text" autofocus>
|
18
|
+
<input type="hidden" id="name" value="USER_<%=current_user.id%>">
|
19
|
+
</fieldset>
|
20
|
+
</form>
|
21
|
+
</div> <!-- end chat -->
|
22
|
+
<%else%>
|
23
|
+
<div class="form">
|
24
|
+
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
25
|
+
<div class="field">
|
26
|
+
<%= f.label :email %><br />
|
27
|
+
<%= f.email_field :email, autofocus: true, autocomplete: "email", :class => "form-fields" %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="field">
|
31
|
+
<%= f.label :password %><br />
|
32
|
+
<%= f.password_field :password, autocomplete: "off" , :class => "form-fields"%>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<% if devise_mapping.rememberable? -%>
|
36
|
+
<div class="field">
|
37
|
+
<%= f.check_box :remember_me %>
|
38
|
+
<%= f.label :remember_me %>
|
39
|
+
</div>
|
40
|
+
<% end -%>
|
41
|
+
|
42
|
+
<div class="actions">
|
43
|
+
<%= f.submit "Log in" %>
|
44
|
+
</div>
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
<%= render "devise/shared/links" %>
|
48
|
+
</div>
|
49
|
+
<%end%>
|
50
|
+
</div> <!-- end live-chat -->
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
<style>
|
55
|
+
@charset "utf-8";
|
56
|
+
/* CSS Document */
|
57
|
+
|
58
|
+
/* ---------- GENERAL ---------- */
|
59
|
+
|
60
|
+
body {
|
61
|
+
background: #e9e9e9;
|
62
|
+
color: #9a9a9a;
|
63
|
+
font: 100%/1.5em "Droid Sans", sans-serif;
|
64
|
+
margin: 0;
|
65
|
+
}
|
66
|
+
|
67
|
+
a { text-decoration: none; }
|
68
|
+
|
69
|
+
fieldset {
|
70
|
+
border: 0;
|
71
|
+
margin: 0;
|
72
|
+
padding: 0;
|
73
|
+
}
|
74
|
+
.form-fields {
|
75
|
+
font-size: 16px;
|
76
|
+
background: aliceblue;
|
77
|
+
width: 100%;
|
78
|
+
}
|
79
|
+
.form{
|
80
|
+
background-color: white;
|
81
|
+
}
|
82
|
+
h4, h5 {
|
83
|
+
line-height: 1.5em;
|
84
|
+
margin: 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
hr {
|
88
|
+
background: #e9e9e9;
|
89
|
+
border: 0;
|
90
|
+
-moz-box-sizing: content-box;
|
91
|
+
box-sizing: content-box;
|
92
|
+
height: 1px;
|
93
|
+
margin: 0;
|
94
|
+
min-height: 1px;
|
95
|
+
}
|
96
|
+
|
97
|
+
img {
|
98
|
+
border: 0;
|
99
|
+
display: block;
|
100
|
+
height: auto;
|
101
|
+
max-width: 100%;
|
102
|
+
}
|
103
|
+
|
104
|
+
input {
|
105
|
+
border: 0;
|
106
|
+
color: inherit;
|
107
|
+
font-family: inherit;
|
108
|
+
font-size: 100%;
|
109
|
+
line-height: normal;
|
110
|
+
margin: 0;
|
111
|
+
}
|
112
|
+
|
113
|
+
p { margin: 0; }
|
114
|
+
|
115
|
+
.clearfix { *zoom: 1; } /* For IE 6/7 */
|
116
|
+
.clearfix:before, .clearfix:after {
|
117
|
+
content: "";
|
118
|
+
display: table;
|
119
|
+
}
|
120
|
+
.clearfix:after { clear: both; }
|
121
|
+
|
122
|
+
/* ---------- LIVE-CHAT ---------- */
|
123
|
+
|
124
|
+
#live-chat {
|
125
|
+
bottom: 0;
|
126
|
+
font-size: 12px;
|
127
|
+
right: 24px;
|
128
|
+
position: fixed;
|
129
|
+
width: 300px;
|
130
|
+
}
|
131
|
+
|
132
|
+
#live-chat header {
|
133
|
+
background: #293239;
|
134
|
+
border-radius: 5px 5px 0 0;
|
135
|
+
color: #fff;
|
136
|
+
cursor: pointer;
|
137
|
+
padding: 16px 24px;
|
138
|
+
}
|
139
|
+
|
140
|
+
#live-chat h4:before {
|
141
|
+
background: #1a8a34;
|
142
|
+
border-radius: 50%;
|
143
|
+
content: "";
|
144
|
+
display: inline-block;
|
145
|
+
height: 8px;
|
146
|
+
margin: 0 8px 0 0;
|
147
|
+
width: 8px;
|
148
|
+
}
|
149
|
+
|
150
|
+
#live-chat h4 {
|
151
|
+
font-size: 12px;
|
152
|
+
}
|
153
|
+
|
154
|
+
#live-chat h5 {
|
155
|
+
font-size: 10px;
|
156
|
+
}
|
157
|
+
|
158
|
+
#live-chat form {
|
159
|
+
padding: 24px;
|
160
|
+
}
|
161
|
+
|
162
|
+
#live-chat input[type="text"] {
|
163
|
+
border: 1px solid #ccc;
|
164
|
+
border-radius: 3px;
|
165
|
+
padding: 8px;
|
166
|
+
outline: none;
|
167
|
+
width: 234px;
|
168
|
+
}
|
169
|
+
|
170
|
+
.chat-message-counter {
|
171
|
+
background: #e62727;
|
172
|
+
border: 1px solid #fff;
|
173
|
+
border-radius: 50%;
|
174
|
+
display: none;
|
175
|
+
font-size: 12px;
|
176
|
+
font-weight: bold;
|
177
|
+
height: 28px;
|
178
|
+
left: 0;
|
179
|
+
line-height: 28px;
|
180
|
+
margin: -15px 0 0 -15px;
|
181
|
+
position: absolute;
|
182
|
+
text-align: center;
|
183
|
+
top: 0;
|
184
|
+
width: 28px;
|
185
|
+
}
|
186
|
+
|
187
|
+
.chat-close {
|
188
|
+
background: #1b2126;
|
189
|
+
border-radius: 50%;
|
190
|
+
color: #fff;
|
191
|
+
display: block;
|
192
|
+
float: right;
|
193
|
+
font-size: 10px;
|
194
|
+
height: 16px;
|
195
|
+
line-height: 16px;
|
196
|
+
margin: 2px 0 0 0;
|
197
|
+
text-align: center;
|
198
|
+
width: 16px;
|
199
|
+
}
|
200
|
+
|
201
|
+
.chat {
|
202
|
+
background: #fff;
|
203
|
+
}
|
204
|
+
|
205
|
+
.chat-history {
|
206
|
+
height: 252px;
|
207
|
+
padding: 8px 24px;
|
208
|
+
overflow-y: scroll;
|
209
|
+
}
|
210
|
+
|
211
|
+
.chat-message {
|
212
|
+
margin: 16px 0;
|
213
|
+
}
|
214
|
+
|
215
|
+
.chat-message img {
|
216
|
+
border-radius: 50%;
|
217
|
+
float: left;
|
218
|
+
}
|
219
|
+
|
220
|
+
.chat-message-content {
|
221
|
+
margin-left: 56px;
|
222
|
+
}
|
223
|
+
|
224
|
+
.chat-time {
|
225
|
+
float: right;
|
226
|
+
font-size: 10px;
|
227
|
+
}
|
228
|
+
|
229
|
+
.chat-feedback {
|
230
|
+
font-style: italic;
|
231
|
+
margin: 0 0 0 80px;
|
232
|
+
}
|
233
|
+
</style>
|
234
|
+
|
235
|
+
<script>
|
236
|
+
(function() {
|
237
|
+
|
238
|
+
$('#live-chat header').on('click', function() {
|
239
|
+
|
240
|
+
$('.chat').slideToggle(300, 'swing');
|
241
|
+
$('.chat-message-counter').fadeToggle(300, 'swing');
|
242
|
+
|
243
|
+
});
|
244
|
+
|
245
|
+
$('.chat-close').on('click', function(e) {
|
246
|
+
|
247
|
+
e.preventDefault();
|
248
|
+
$('#live-chat').fadeOut(300);
|
249
|
+
|
250
|
+
});
|
251
|
+
|
252
|
+
}) ();
|
253
|
+
</script>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ChatChannel < ApplicationCable::Channel
|
2
|
+
# Called when the consumer has successfully
|
3
|
+
# become a subscriber of this channel.
|
4
|
+
|
5
|
+
def subscribed
|
6
|
+
stream_from "chat_#{params[:room]}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def receive(data)
|
10
|
+
data["time"] = Time.now.strftime("at %I:%M%p")
|
11
|
+
ActionCable.server.broadcast("chat_#{params[:room]}", data)
|
12
|
+
RubyBotJob.perform_later data,params[:room]
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class RubyBotJob < ApplicationJob
|
2
|
+
queue_as :default
|
3
|
+
|
4
|
+
def perform(data,room_id)
|
5
|
+
data["body"] = Rails::Bot.conversation(data["body"])
|
6
|
+
data["sent_by"] = "Bot"
|
7
|
+
data["time"] = Time.now.strftime("at %I:%M%p")
|
8
|
+
ActionCable.server.broadcast("chat_#{room_id}", data)
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Himanshu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -49,10 +49,16 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- lib/rails/bot.rb
|
52
|
+
- lib/rails/bot/initializer_generator.rb
|
52
53
|
- lib/rails/bot/railtie.rb
|
53
54
|
- lib/rails/bot/version.rb
|
54
55
|
- lib/tasks/rails/bot_tasks.rake
|
55
56
|
- lib/tasks/rails_bot.rake
|
57
|
+
- lib/templates/chat.coffee
|
58
|
+
- lib/templates/chat.html.erb
|
59
|
+
- lib/templates/chat_channel.rb
|
60
|
+
- lib/templates/google_initializer.rb
|
61
|
+
- lib/templates/ruby_bot_job.rb
|
56
62
|
homepage: ''
|
57
63
|
licenses:
|
58
64
|
- MIT
|