chatterbot 2.0.5 → 2.1.0
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 +5 -5
- data/.github/workflows/ci.yml +19 -0
- data/Gemfile +2 -2
- data/README.markdown +7 -21
- data/chatterbot.gemspec +3 -3
- data/docs/_site/advanced.html +43 -54
- data/docs/_site/configuration.html +23 -43
- data/docs/_site/contributing.html +18 -37
- data/docs/_site/deploying.html +44 -61
- data/docs/_site/examples.html +108 -123
- data/docs/_site/features.html +70 -71
- data/docs/_site/index.html +43 -64
- data/docs/_site/other-tools.html +22 -41
- data/docs/_site/rdoc.html +17 -36
- data/docs/_site/setup.html +62 -71
- data/docs/_site/tut.html +16 -36
- data/docs/_site/twitter-docs.html +17 -36
- data/docs/_site/walkthrough.html +35 -51
- data/docs/advanced.md +0 -5
- data/docs/deploying.md +0 -6
- data/docs/examples.md +0 -48
- data/docs/index.md +2 -3
- data/lib/chatterbot.rb +0 -1
- data/lib/chatterbot/bot.rb +5 -68
- data/lib/chatterbot/client.rb +2 -9
- data/lib/chatterbot/config.rb +0 -1
- data/lib/chatterbot/dsl.rb +0 -43
- data/lib/chatterbot/skeleton.rb +0 -2
- data/lib/chatterbot/version.rb +1 -1
- data/spec/bot_spec.rb +1 -76
- data/spec/client_spec.rb +0 -3
- data/spec/config_manager_spec.rb +6 -5
- data/spec/config_spec.rb +4 -1
- data/spec/dsl_spec.rb +1 -33
- data/templates/skeleton.txt +0 -47
- metadata +13 -21
- data/.document +0 -5
- data/.travis.yml +0 -9
- data/docs/_site/streaming.html +0 -506
- data/docs/streaming.md +0 -98
- data/examples/streaming_bot.rb +0 -49
- data/lib/chatterbot/streaming.rb +0 -72
- data/spec/streaming_spec.rb +0 -172
data/spec/config_spec.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
require 'tempfile'
|
3
|
+
require 'tmpdir'
|
3
4
|
|
4
5
|
describe "Chatterbot::Config" do
|
5
6
|
before(:each) do
|
6
7
|
@bot = Chatterbot::Bot.new
|
7
|
-
|
8
|
+
tempdir = Dir.tmpdir
|
9
|
+
@tmp_config_dest = File.join(tempdir, 'bot.yml')
|
8
10
|
allow(@bot).to receive(:config_file).and_return(@tmp_config_dest)
|
9
11
|
end
|
12
|
+
|
10
13
|
after(:each) do
|
11
14
|
if File.exist?(@tmp_config_dest)
|
12
15
|
File.unlink(@tmp_config_dest)
|
data/spec/dsl_spec.rb
CHANGED
@@ -100,7 +100,7 @@ describe "Chatterbot::DSL" do
|
|
100
100
|
|
101
101
|
describe "search" do
|
102
102
|
it "passes along to bot object" do
|
103
|
-
allow(@bot).to receive(:
|
103
|
+
allow(@bot).to receive(:run!)
|
104
104
|
expect(@bot).to receive(:register_handler).with(:search, ["foo"])
|
105
105
|
search("foo") {}
|
106
106
|
end
|
@@ -118,39 +118,7 @@ describe "Chatterbot::DSL" do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
describe "favorited" do
|
122
|
-
it "passes along to bot object" do
|
123
|
-
expect(@bot).to receive(:register_handler).with(:favorited, instance_of(Proc))
|
124
|
-
|
125
|
-
favorited {}
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "followed" do
|
130
|
-
it "passes along to bot object" do
|
131
|
-
expect(@bot).to receive(:register_handler).with(:followed, instance_of(Proc))
|
132
|
-
|
133
|
-
followed {}
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "deleted" do
|
138
|
-
it "passes along to bot object" do
|
139
|
-
expect(@bot).to receive(:register_handler).with(:deleted, instance_of(Proc))
|
140
|
-
|
141
|
-
deleted {}
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
121
|
|
146
|
-
describe "streaming" do
|
147
|
-
it "passes along to bot object" do
|
148
|
-
expect(@bot).to receive(:streaming=).with(true)
|
149
|
-
use_streaming
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
122
|
it "#retweet passes along to bot object" do
|
155
123
|
expect(@bot).to receive(:retweet).with(1234)
|
156
124
|
retweet(1234)
|
data/templates/skeleton.txt
CHANGED
@@ -94,14 +94,6 @@ exclude bad_words
|
|
94
94
|
# will be rejected
|
95
95
|
only_interact_with_followers
|
96
96
|
|
97
|
-
#
|
98
|
-
# Specifying 'use_streaming' will cause Chatterbot to use Twitter's
|
99
|
-
# Streaming API. Your bot will run constantly, listening for tweets.
|
100
|
-
# Alternatively, you can run your bot as a cron/scheduled job. In that
|
101
|
-
# case, do not use this line. Every time you run your bot, it will
|
102
|
-
# execute once, and then exit.
|
103
|
-
#
|
104
|
-
use_streaming
|
105
97
|
|
106
98
|
#
|
107
99
|
# Here's the fun stuff!
|
@@ -148,43 +140,4 @@ use_streaming
|
|
148
140
|
# home_timeline do |tweet|
|
149
141
|
# puts tweet.inspect
|
150
142
|
# end
|
151
|
-
|
152
|
-
#
|
153
|
-
# Use this block if you want to be notified about new followers of
|
154
|
-
# your bot. You might do this to follow the user back.
|
155
|
-
#
|
156
|
-
# NOTE: This block only works with the Streaming API. If you use it,
|
157
|
-
# chatterbot will assume you want to use streaming and will
|
158
|
-
# automatically activate it for you.
|
159
|
-
#
|
160
|
-
# followed do |user|
|
161
|
-
# puts user.inspect
|
162
|
-
# end
|
163
|
-
|
164
|
-
#
|
165
|
-
# Use this block if you want to be notified when one of your tweets is
|
166
|
-
# favorited. The object passed in will be a Twitter::Streaming::Event
|
167
|
-
# @see http://www.rubydoc.info/gems/twitter/Twitter/Streaming/Event
|
168
|
-
#
|
169
|
-
# NOTE: This block only works with the Streaming API. If you use it,
|
170
|
-
# chatterbot will assume you want to use streaming and will
|
171
|
-
# automatically activate it for you.
|
172
|
-
#
|
173
|
-
# favorited do |event|
|
174
|
-
# puts event.inspect
|
175
|
-
# end
|
176
|
-
|
177
|
-
#
|
178
|
-
# Use this block if you want to be notified of deleted tweets from
|
179
|
-
# your bots home timeline. The object passed in will be a
|
180
|
-
# Twitter::Streaming::DeletedTweet
|
181
|
-
# @see http://www.rubydoc.info/gems/twitter/Twitter/Streaming/DeletedTweet
|
182
|
-
#
|
183
|
-
# NOTE: This block only works with the Streaming API. If you use it,
|
184
|
-
# chatterbot will assume you want to use streaming and will
|
185
|
-
# automatically activate it for you.
|
186
|
-
#
|
187
|
-
#deleted do |tweet|
|
188
|
-
#
|
189
|
-
#end
|
190
143
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatterbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Mitchell
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.5.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: twitter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: launchy
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.0'
|
83
83
|
description: A ruby framework for writing bots that run on Twitter. Comes with a simple
|
84
84
|
DSL for easy coding.
|
85
85
|
email: colin@muffinlabs.com
|
@@ -89,9 +89,8 @@ extensions:
|
|
89
89
|
- ext/mkrf_conf.rb
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
|
-
- ".
|
92
|
+
- ".github/workflows/ci.yml"
|
93
93
|
- ".gitignore"
|
94
|
-
- ".travis.yml"
|
95
94
|
- Gemfile
|
96
95
|
- LICENSE.txt
|
97
96
|
- README.markdown
|
@@ -126,7 +125,6 @@ files:
|
|
126
125
|
- docs/_site/params.json
|
127
126
|
- docs/_site/rdoc.html
|
128
127
|
- docs/_site/setup.html
|
129
|
-
- docs/_site/streaming.html
|
130
128
|
- docs/_site/stylesheets/pygment_trac.css
|
131
129
|
- docs/_site/stylesheets/stylesheet.css
|
132
130
|
- docs/_site/tut.html
|
@@ -152,7 +150,6 @@ files:
|
|
152
150
|
- docs/params.json
|
153
151
|
- docs/rdoc.md
|
154
152
|
- docs/setup.md
|
155
|
-
- docs/streaming.md
|
156
153
|
- docs/stylesheets/pygment_trac.css
|
157
154
|
- docs/stylesheets/stylesheet.css
|
158
155
|
- docs/tips.md
|
@@ -164,7 +161,6 @@ files:
|
|
164
161
|
- examples/dsl_test.rb
|
165
162
|
- examples/echoes_bot.rb
|
166
163
|
- examples/search_bot.rb
|
167
|
-
- examples/streaming_bot.rb
|
168
164
|
- ext/mkrf_conf.rb
|
169
165
|
- lib/chatterbot.rb
|
170
166
|
- lib/chatterbot/blocklist.rb
|
@@ -186,7 +182,6 @@ files:
|
|
186
182
|
- lib/chatterbot/safelist.rb
|
187
183
|
- lib/chatterbot/search.rb
|
188
184
|
- lib/chatterbot/skeleton.rb
|
189
|
-
- lib/chatterbot/streaming.rb
|
190
185
|
- lib/chatterbot/tweet.rb
|
191
186
|
- lib/chatterbot/ui.rb
|
192
187
|
- lib/chatterbot/utils.rb
|
@@ -211,7 +206,6 @@ files:
|
|
211
206
|
- spec/search_spec.rb
|
212
207
|
- spec/skeleton_spec.rb
|
213
208
|
- spec/spec_helper.rb
|
214
|
-
- spec/streaming_spec.rb
|
215
209
|
- spec/tweet_spec.rb
|
216
210
|
- spec/utils_spec.rb
|
217
211
|
- spec/whitelist_spec.rb
|
@@ -221,7 +215,7 @@ homepage: http://github.com/muffinista/chatterbot
|
|
221
215
|
licenses:
|
222
216
|
- MIT
|
223
217
|
metadata: {}
|
224
|
-
post_install_message:
|
218
|
+
post_install_message:
|
225
219
|
rdoc_options: []
|
226
220
|
require_paths:
|
227
221
|
- lib
|
@@ -236,9 +230,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
230
|
- !ruby/object:Gem::Version
|
237
231
|
version: '0'
|
238
232
|
requirements: []
|
239
|
-
|
240
|
-
|
241
|
-
signing_key:
|
233
|
+
rubygems_version: 3.0.8
|
234
|
+
signing_key:
|
242
235
|
specification_version: 4
|
243
236
|
summary: A ruby framework for writing Twitter bots
|
244
237
|
test_files:
|
@@ -262,7 +255,6 @@ test_files:
|
|
262
255
|
- spec/search_spec.rb
|
263
256
|
- spec/skeleton_spec.rb
|
264
257
|
- spec/spec_helper.rb
|
265
|
-
- spec/streaming_spec.rb
|
266
258
|
- spec/tweet_spec.rb
|
267
259
|
- spec/utils_spec.rb
|
268
260
|
- spec/whitelist_spec.rb
|
data/.document
DELETED
data/.travis.yml
DELETED
data/docs/_site/streaming.html
DELETED
@@ -1,506 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
6
|
-
<meta name="viewport" content="width=device-width">
|
7
|
-
|
8
|
-
<title>chatterbot : Streaming API</title>
|
9
|
-
<meta name="description" content="twitter bots in ruby">
|
10
|
-
|
11
|
-
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
|
12
|
-
<link rel="stylesheet" href="/css/syntax.css">
|
13
|
-
<link rel="stylesheet" href="/css/main.css">
|
14
|
-
</head>
|
15
|
-
<body>
|
16
|
-
|
17
|
-
<div class="container">
|
18
|
-
<div class=row-fluid>
|
19
|
-
<div id=header class=span12>
|
20
|
-
<h4><a class=brand href="/">chatterbot</a>
|
21
|
-
<small>twitter bots in ruby</small>
|
22
|
-
</h4>
|
23
|
-
|
24
|
-
|
25
|
-
</div>
|
26
|
-
</div>
|
27
|
-
|
28
|
-
<div class=row-fluid>
|
29
|
-
|
30
|
-
|
31
|
-
<div id=navigation class=span2>
|
32
|
-
<ul class="nav nav-list">
|
33
|
-
<li><a href="/">Home</a></li>
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
<li class=nav-header>Getting Started</li>
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
<li data-order="">
|
58
|
-
|
59
|
-
<a href="/examples.html">Examples</a>
|
60
|
-
|
61
|
-
</li>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
<li data-order="">
|
84
|
-
|
85
|
-
<a href="/setup.html">Authorizing Your Bot</a>
|
86
|
-
|
87
|
-
</li>
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
<li data-order="">
|
106
|
-
|
107
|
-
<a href="/walkthrough.html">Walkthrough</a>
|
108
|
-
|
109
|
-
</li>
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
<li class=nav-header>Documentation</li>
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
<li data-order="">
|
121
|
-
|
122
|
-
<a href="/advanced.html">Advanced Features</a>
|
123
|
-
|
124
|
-
</li>
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
<li data-order="">
|
131
|
-
|
132
|
-
<a href="/configuration.html">Configuration</a>
|
133
|
-
|
134
|
-
</li>
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
<li data-order="">
|
145
|
-
|
146
|
-
<a href="/deploying.html">Running your Bot</a>
|
147
|
-
|
148
|
-
</li>
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
<li data-order="">
|
159
|
-
|
160
|
-
<a href="/features.html">Basic Features</a>
|
161
|
-
|
162
|
-
</li>
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
<li data-order="">
|
185
|
-
|
186
|
-
<a href="/streaming.html">Streaming API</a>
|
187
|
-
|
188
|
-
</li>
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
<li class=nav-header>Developers</li>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
<li data-order="">
|
220
|
-
|
221
|
-
<a href="/contributing.html">Contributing</a>
|
222
|
-
|
223
|
-
</li>
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
<li class=nav-header>Resources</li>
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
<li data-order="">
|
307
|
-
|
308
|
-
<a href="/other-tools.html">Other Tools</a>
|
309
|
-
|
310
|
-
</li>
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
<li data-order="">
|
317
|
-
|
318
|
-
<a href="http://rubydoc.info/gems/chatterbot">rdoc</a>
|
319
|
-
|
320
|
-
</li>
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
<li data-order="">
|
339
|
-
|
340
|
-
<a href="https://dev.twitter.com/rest/public">Twitter API docs</a>
|
341
|
-
|
342
|
-
</li>
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
<!-- List additional links. It is recommended to add a divider
|
352
|
-
e.g. <li class=divider></li> first to break up the content. -->
|
353
|
-
</ul>
|
354
|
-
|
355
|
-
</div>
|
356
|
-
|
357
|
-
<div id=content class=span10>
|
358
|
-
<div class=page-header>
|
359
|
-
<h2>Streaming API
|
360
|
-
|
361
|
-
</h2>
|
362
|
-
</div>
|
363
|
-
|
364
|
-
<p>Chatterbot has basic support for Twitter's <a href="https://dev.twitter.com/streaming/overview">Streaming API</a>. If
|
365
|
-
you are an advanced developer, or want to create something very
|
366
|
-
involved, it might make more sense to use a different library.
|
367
|
-
However, if you do use Chatterbot, you can continue to use the DSL,
|
368
|
-
and you get access to a bunch of helpful routines.</p>
|
369
|
-
|
370
|
-
<p>Here's an example bot using the Streaming API:</p>
|
371
|
-
<div class="highlight"><pre><code class="language-text" data-lang="text">#!/usr/bin/env ruby
|
372
|
-
|
373
|
-
## This is a very simple working example of a bot using the streaming
|
374
|
-
## API. It's basically a copy of echoes_bot.rb, just using streaming.
|
375
|
-
|
376
|
-
#
|
377
|
-
# require the dsl lib to include all the methods you see below.
|
378
|
-
#
|
379
|
-
require 'rubygems'
|
380
|
-
require 'chatterbot/dsl'
|
381
|
-
|
382
|
-
consumer_secret 'foo'
|
383
|
-
secret 'bar'
|
384
|
-
token 'biz'
|
385
|
-
consumer_key 'bam'
|
386
|
-
|
387
|
-
|
388
|
-
puts "Loading echoes_bot.rb using the streaming API"
|
389
|
-
|
390
|
-
exclude "http://", "https://"
|
391
|
-
|
392
|
-
blacklist "mean_user, private_user"
|
393
|
-
|
394
|
-
streaming do
|
395
|
-
favorited do |user, tweet|
|
396
|
-
reply "@#{user.screen_name} thanks for the fave!", tweet
|
397
|
-
end
|
398
|
-
|
399
|
-
followed do |user|
|
400
|
-
tweet "@#{user.screen_name} just followed me!"
|
401
|
-
follow user
|
402
|
-
end
|
403
|
-
|
404
|
-
replies do |tweet|
|
405
|
-
favorite tweet
|
406
|
-
|
407
|
-
puts "It's a tweet!"
|
408
|
-
src = tweet.text.gsub(/@echoes_bot/, "#USER#")
|
409
|
-
reply src, tweet
|
410
|
-
end
|
411
|
-
end
|
412
|
-
</code></pre></div>
|
413
|
-
<p>By default, chatterbot will use the
|
414
|
-
<a href="https://dev.twitter.com/streaming/userstreams">user endpoint</a>, which
|
415
|
-
returns events for the bot -- mentions, follows, etc. If you want to
|
416
|
-
perform a search, or use the sample endpoint, you will need to specify
|
417
|
-
that:</p>
|
418
|
-
<div class="highlight"><pre><code class="language-text" data-lang="text">#
|
419
|
-
# sample the twitter stream
|
420
|
-
#
|
421
|
-
streaming(endpoint:"sample") do
|
422
|
-
sample do |tweet|
|
423
|
-
puts tweet.text
|
424
|
-
end
|
425
|
-
end
|
426
|
-
</code></pre></div><div class="highlight"><pre><code class="language-text" data-lang="text">#
|
427
|
-
# run a search
|
428
|
-
#
|
429
|
-
streaming(endpoint:"search") do
|
430
|
-
search("Streaming API") do |tweet|
|
431
|
-
puts tweet.text
|
432
|
-
end
|
433
|
-
end
|
434
|
-
</code></pre></div><div class="highlight"><pre><code class="language-text" data-lang="text">#
|
435
|
-
# find geocoded tweets
|
436
|
-
#
|
437
|
-
streaming(endpoint: :filter, locations:"-180,-90,180,90") do
|
438
|
-
user do |tweet|
|
439
|
-
puts tweet.text
|
440
|
-
end
|
441
|
-
end
|
442
|
-
</code></pre></div>
|
443
|
-
|
444
|
-
</div>
|
445
|
-
|
446
|
-
</div>
|
447
|
-
|
448
|
-
<div class=row-fluid>
|
449
|
-
<div id=footer class=span12>
|
450
|
-
Documentation for <a href="https://github.com/muffinista/chatterbot">chatterbot</a>
|
451
|
-
|
452
|
-
</div>
|
453
|
-
</div>
|
454
|
-
</div>
|
455
|
-
|
456
|
-
<script>
|
457
|
-
function orderNav() {
|
458
|
-
var list,
|
459
|
-
section,
|
460
|
-
header,
|
461
|
-
sections = [],
|
462
|
-
lists = {},
|
463
|
-
headers = {};
|
464
|
-
|
465
|
-
var navUl = document.querySelectorAll('#navigation ul')[0],
|
466
|
-
navLis = document.querySelectorAll('#navigation ul li');
|
467
|
-
|
468
|
-
if (!navUl) return;
|
469
|
-
|
470
|
-
for (var i = 0; i < navLis.length; i++) {
|
471
|
-
var order, li = navLis[i];
|
472
|
-
|
473
|
-
if (li.classList.contains('nav-header')) {
|
474
|
-
section = li.textContent || li.innerText;
|
475
|
-
sections.push(section);
|
476
|
-
headers[section] = li;
|
477
|
-
continue;
|
478
|
-
}
|
479
|
-
|
480
|
-
if (!lists[section]) {
|
481
|
-
lists[section] = [];
|
482
|
-
}
|
483
|
-
|
484
|
-
order = parseFloat(li.getAttribute('data-order'))
|
485
|
-
lists[section].push([order, li]);
|
486
|
-
}
|
487
|
-
|
488
|
-
for (var i = 0; i < sections.length; i++) {
|
489
|
-
section = sections[i];
|
490
|
-
list = lists[section].sort(function(a, b) {
|
491
|
-
return a[0] - b[0];
|
492
|
-
});
|
493
|
-
|
494
|
-
if (header = headers[section]) {
|
495
|
-
navUl.appendChild(header);
|
496
|
-
}
|
497
|
-
for (var j = 0; j < list.length; j++) {
|
498
|
-
navUl.appendChild(list[j][1]);
|
499
|
-
}
|
500
|
-
}
|
501
|
-
}
|
502
|
-
|
503
|
-
if (document.querySelectorAll) orderNav();
|
504
|
-
</script>
|
505
|
-
</body>
|
506
|
-
</html>
|